Neo Neo - 12 days ago 9
Javascript Question

Angularjs oauth Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Authorization: Bearer ' is not a valid HTTP header field name

My code for making GET call is



$http({
url: '/user/info/',
method: "GET",
headers: {
'Authorization: Bearer ': String(JSON.parse($cookies.authenticatedAccount).access_token)
},
withCredentials: true
});





With the above code getting issue: "Error: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'Authorization: Bearer ' is not a valid HTTP header field name."

Any idea what may be issue ?

Answer

Use

...
headers: {
  'Authorization': 'Bearer '+String(JSON.parse($cookies.authenticatedAccount).access_token)
},
...
Comments