I am invoking the service with authorization header, but I am getting the http status code 401 unauthorized access, interesting thing is that if i try this with chrome or postman I am getting exactly result , that means there is no issue on server side ,then what I am missing in client side so that it is failing on options method?
Here is my code for that :-
this.http.get(url,{headers:this.headers}).subscribe(res=>{
console.log(res);
});
Sorry I don't have enough reputation to comment so I have to reply.
If you install Chors Extension for Chrome and it posts successfully, then the problem is likely because you are trying to access a service that you are not authorised to from a localhost.
My recommended solution would be to allow all relevant headers on your server, such as (pseudo):
Access-Control-Allow-Origin: localhost:8888
Access-Control-Allow-Methods: GET, POST, PUT, DELETE
Access-Control-Allow-Headers: Content-Type
If you have access to the receiving server, the easiest fix would be to add
Access-Control-Allow-Origin: *
to your server ( taken from here ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.