I am trying to call a Web Api endpoint from Angular 2. In IE and Chrome it all works fine but in Firefox I get a json parse error. I think its returning XML instead of Json. I thought that setting the content-type would have fixed this. Does my code look correct? Any ideas?
let _tileUrl = XXX;
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.get(_tileUrl, options)
.map((response: Response) => <ITile[]>response.json())
.catch(this.handleError);
I think that you should use the Accept
header instead:
let headers = new Headers({ 'Accept': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.get(_tileUrl, options)
.map((response: Response) => <ITile[]>response.json())
.catch(this.handleError);
The Content-Type
header describes the type of content you send. Accept
the content you expect in the response...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With