Set headers on get request angular 2 -


i try set authorization header request authenticate users rest api. i'm using angular 2 rc1. (i'am total beginner).

gettest(){     let authtoken = localstorage.getitem('auth_token');     let headers = new headers({ 'content-type': 'application/json' });     headers.append('authorization', `bearer ${authtoken}`);      let options = new requestoptions({ headers: headers });     return this._http       .get(this._url,options)       .map(res => console.log(res));   } 

i allow cors in backend.

header("access-control-allow-origin: *"); header("access-control-request-headers: content-type, authorization"); 

my console :

options api/userprofile/

xmlhttprequest cannot load /userprofile/. response preflight has invalid http status code 406

my request headers

any idea ?

i think need accept header rather because of 406 status code...

let authtoken = localstorage.getitem('auth_token'); let headers = new headers({ 'accept': 'application/json' }); headers.append('authorization', `bearer ${authtoken}`);  let options = new requestoptions({ headers: headers }); return this._http   .get(this._url,options)   .map(res => console.log(res)); 

this allows tell server content type expect in response...

the content-type header rather specify type of content sent in request. in case, there no content...


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -