I am using npm 'isomorphic-fetch' to send requests. The problem I am experiencing is I am unable to set the content-type of the request header.
I set a content type of application/json , however the request header are being set to text/plain.
import 'isomorphic-fetch';
sendRequest(url, method, body) {
const options = {
method: method,
headers:{'content-type': 'application/json'},
mode: 'no-cors'
};
options.body = JSON.stringify(body);
return fetch(url, options);
}
When I examine the request in my browser the content type is o :
content-type:text/plain;charset=UTF-8
Can anyone explain why I am unable to set this property?
You need to create a fetch headers object.
I found the answer after reading the following article:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Headers
When the options mode property is set to no-cors the request header values are immutable.
Instead I set the mode property to cors.