I\'ve tried to use fetch to call from backend using react, without libs (such as Axios). So I created this function:
export function api(url, method, body, i
In my case it occurred because I wrote "Content Type" instead of "Content-Type"
I got the same problem, but working with Angular 7, I was using a Interceptor service like this:
// headerservice.ts
public intercept() {
const token = Cookies.get('token');
this.Language = Cookies.get('language');
this.headers = new HttpHeaders(
{
Authorization: 'JWT ' + token,
'Accept-Language': this.Language
}
);
return this.headers;
}
//other file
this.headers = this.headersService.intercept();
But it doesn´t work on the other file where i am doing the fetch, so i remove the service and put the headers directly inside the function and it works! like this:
const token = Cookies.get('token');
const language = Cookies.get('language');
const headers = {
Authorization: 'JWT ' + token,
'Accept-Language': language
}
const fetchParams = { method: 'GET',
headers: (headers) };
fetch(url, fetchParams)