8
I need to perform a POST request using angular (http.post) and I need to pass to my API (.NET) in my header the access credentials (I’m using basic Authentication).
Authorization:Basic dXNlcm5hbWU6cGFzc3dvcmQ=
At the angle I change the header as I need
$http.defaults.headers.common.Authorization = 'Basic ' + credentials;
But the moment I perform the POST for the API, Angular (or browser) changes my POST to OPTIONS
Request Method:OPTIONS
I have searched several places about, but could not find a solution. On the Web.Config of my API I have already configured to allow CORS.
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:9000" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, Cache-Control" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
Can anyone tell me what I might be doing wrong? How to find the solution? Thanks in advance!
One addendum only. You can configure the hosts file of the local machine to go up the frontend with the url http:/example.com (you need to go up Angular at port 80, default for web applications). So you can, at development time, communicate well with your API.
– rogerdossantos