matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

Unable to set Content-Type Header in POST request #155

Open NiiMER opened 6 years ago

NiiMER commented 6 years ago

While using fetch from isomorphic-fetch it can't send the request in application/json type, it keeps sending plain/text.

After using fetch from node-fetch plugin it works!!

kaistullich commented 6 years ago

When calling ‘fetch()’, for the 2nd parameter do you define a ‘headers’ key:value?

NiiMER commented 6 years ago

Yes like the following: fetch('http://example.domain/api/v0.2/login/', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ userName: this.state.usernameOrEmail, password: this.state.password, }), cridentials: 'include', mode: 'no-cors', })

gary1410 commented 6 years ago

Do you get back and OPTIONS request?

Also, this might be a CORs issue.

https://github.com/github/fetch/issues/143#issuecomment-106774938