i have a codeigniter api and i am trying to post request with authorization header
but this not working for me and chrome console return 404 error In Api They Call Without Authorization Header Is Working Fine How To Set Headers For It?
ionViewWillEnter(){
let headers:Headers = new Headers({
'Content-Type': 'application/json',
'Authorization': this.token
});
let options: RequestOptions = new RequestOptions({headers:headers});
let params: URLSearchParams = new URLSearchParams();
params.append('latitude','23.259933');
params.append('longitude','77.412615');
params.append('nearby','5');
this.http.post(url, params, options)
.subscribe(
(success: Response)=>{
console.log(success);
},(err: Response)=>{
console.log(err.json());
}
)
}
The error message is the important bit: It is doing a preflight request (OPTIONS request to your URI instead of POST) to find out if all the headers are correct, and your API responds with a 404 instead of the wanted 200. Make your API respond correctly.
(Look at your browser’s dev tool’s network panel to see the request it is making)
I have check the browser network tab. Its sending Request type OPTION when i add any Authorization header. It should send POST REQUEST. Why its happening & how can i fix that.
I belive if i will be able to send POST request with header my issue will be resolve. What you think?