I was using angular 4's default Http
module to send http request without any problem. However, I recently replaced the Http
module with AuthHttp
from angular2-jwt
package. Now with AuthHttp
, it stopped sending body as payload to the server in post request. Here is the code:
return this.authHttp.post(url, JSON.stringify(body)).map((res: Response) => {
// ...
});
The code above doesn't send the body as payload to the server. It sends the payload as expected when authHttp is replaced with http.
Not sure if I have done something wrong because it seems there's very few google results about this question.
Update:
With AuthHttp
, Chrome Dev Tools shows only an OPTIONS
request was sent . That's really weird.
Seems AuthHttp is sending some weird OPTIONS request to the server. Chrome shows the following error:
Response for preflight has invalid HTTP status code 400
Problem solved by adding the following code on the server: