Pergunta

I am doing this

// 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');
});

I was expecting to see the same header displayed twice. Instead, the dart call displays

{last-modified: Tue, 18 Mar 2014 18:04:00 GMT, content-type: text/plain; charset=x-user-defined, cache-control: public, max-age=2592000}

and the angular-dart one

{Accept: application/json, text/plain, */*}

The second header is the default one, so I conclude that I'm failing to set properly the header in the angular-dart http call. How can I fix this? Can you spot any other mistake?

Foi útil?

Solução

I think that You are missing one thing here. GET method does not contain any payload, therefore it can't have content type header set.

If you want to override response mime (like in first example) you shouldn't use header because it has different purpose. Unfortunately I can't see a way to override response's mime type in agular's HTTP class. I think there isn't one. So maybe you can use HttpRequest class in your service for now and file an issue report.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top