Reputation: 3787
I have this code on client:
return fetch('http://localhost:8080/api/authenticate', {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'admin',
password: 'admin',
}),
});
When i send this request for some reason Content-Type is substituted to text/plain;charset=UTF-8
. This makes my server side fail the request as it only accepts application/json
requests. What am i doing wrong here?
I am using Chrome 51 and here is my request:
EDIT:
When I remove JSON.strigify()
Content-Type and Request payload are also being omitted.
Here is an example:
Upvotes: 0
Views: 3232
Reputation: 943214
You have set mode: 'no-cors',
so you cannot set 'Content-Type'
to 'application/json'
. It isn't one of the safe values for Content-Type.
Upvotes: 5