我要这么做
// dart
HttpRequest req = new HttpRequest();
req.open('GET', 'some-url');
req.overrideMimeType('text\/plain; charset=x-user-defined');
req.onLoadEnd.listen((e) {
if (req.status == 200) {
print(req.responseHeaders);
} else {
print('download failed');
}
});
req.send();
// angular-dart
_http.get('some-url', headers: {'Content-Type': 'text\/plain; charset=x-user-defined'})
.then((HttpResponse resp) {
print(resp.config.headers);
})
.catchError((e) {
print('download failed');
});我本来希望看到同一个标题显示两次。相反,dart调用显示。
{last-modified: Tue, 18 Mar 2014 18:04:00 GMT, content-type: text/plain; charset=x-user-defined, cache-control: public, max-age=2592000}还有角飞镖
{Accept: application/json, text/plain, */*}第二个标头是默认的,因此我得出结论,我未能在角镖http调用中正确地设置标头。我怎么才能解决这个问题?你能发现其他的错误吗?
发布于 2014-04-21 17:25:03
我觉得你错过了一件事。方法不包含任何有效负载,因此它不能设置内容类型标头。
如果您想要覆盖响应mime (如第一个示例中的那样),则不应该使用header,因为它有不同的用途。不幸的是,我看不到在agular的HTTP类中覆盖响应的mime类型的方法。我想根本就没有。因此,您现在可以在服务中使用HttpRequest类并提交问题报告。
https://stackoverflow.com/questions/23180039
复制相似问题