Having trouble with transmitting headers in a json post from Angular2 beta 8:
import { RequestOptions, RequestMethod, Headers, RequestOptionsArgs, Http } from 'angular2/http';
// ...
let headers = new Headers(),
body = JSON.stringify({ identifier, password });
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
let opts:RequestOptionsArgs = { headers: headers };
this.http.post(this.baseUrl + 'auth/login', body, opts)
.subscribe(
data => console.log(data),
err => console.log(err.json().message),
() => console.log('Authentication Complete')
);
However, the XHR call in Chrome is not showing these headers. Debugging in Chrome indicates that the Content-Type
header is labeled as Provisional Headers are Shown
and shows
Content-Type:text/plain;charset=UTF-8
. It seems like the header values are correct though:
console.log(headers.get('Content-Type')) // => 'application/json'
console.log(headers.get('Accept')) // => 'application/json'
The issue seems to be using RequestHeaders
instead of Headers
. Not sure why it didn't throw an error.