Skip to content

Instantly share code, notes, and snippets.

@dantenovski
Created December 14, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantenovski/b93c8f6561e41ae51579a25516dc2199 to your computer and use it in GitHub Desktop.
Save dantenovski/b93c8f6561e41ae51579a25516dc2199 to your computer and use it in GitHub Desktop.
var token = localStorage.getItem('my_tkn');
var httpHeaders;
//'x-access-token': token
//'Authorization' : token
if(token){
httpHeaders = {
'Content-Type' : 'application/x-www-form-urlencoded',
'Accept' : 'application/json',
'x-access-token' : token
};
} else {
httpHeaders = {
'Content-Type' : 'application/x-www-form-urlencoded',
'Accept' : 'application/json'
};
}
/*
httpHeaders = {
'Content-Type' : 'application/x-www-form-urlencoded',
'Accept' : 'application/json'
};
*/
let options = {
method: 'post',
body: urlEncodedData // login and password
};
options.headers = new Headers(httpHeaders);
const response = yield call(fetch, `http://mysite.com/${path}`, options);
@dantenovski
Copy link
Author

This way the server rejects the HTTP request as malformed. But when I do just like this

httpHeaders = { 
  'Content-Type' : 'application/x-www-form-urlencoded', 
  'Accept' : 'application/json'
};

it works just fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment