I am using Angular2/Http
to do a post request and send some data to a server:
let myheaders = new Headers();
myheaders.append('Content-Type', 'application/json');
let options = new RequestOptions({ headers: myheaders });
let resourceStr = '{"foo": "bar"}';
let foo = this.http.post('http://127.0.0.1:5000/api/invalid', resourceStr, options)
.subscribe(
data => {
console.log(data);
},
error => {
console.warn(error.statusText);
});
If the server responds with NOT FOUND (404)
(eg, my URL is wrong), the error callback of the Observable will be called but the statusText will be set Ok
. However, if I change the Content-Type
in the headers from application/json
to text/plain
, the error callback will be called and the statusText will be set to NOT FOUND
as it is supposed to.
Anybody has the same problem?
PS: I am using Angular2 rc2
Turns out there was a bug in the rc2 version. The rc3 version which was released ~2 days ago fixes this problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.