0

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:

enter image description here

EDIT: When I remove JSON.strigify() Content-Type and Request payload are also being omitted. Here is an example:

Result without JSON.stringify()

ShintoTuna
  • 3,677
  • 8
  • 29
  • 36
  • http://stackoverflow.com/questions/9890662/set-ajax-content-type-header-in-request-from-ie – Will Jun 27 '16 at 18:19

1 Answers1

5

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335