I have the following headers in my WebAPI web.config:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="https://localhost:44379" />
<add name="Access-Control-Allow-Methods" value="*" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With, content-type, Accept, Origin, Authorization, User-Agent, Referer" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
When I send the following POST call in front-end, I get the errors:
"Access to fetch at 'https://server-name/Grouping/api/Grouping/GetGroupByProcessId' from origin 'https://localhost:44379' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status."
and
OPTIONS https://server-name/Grouping/api/Grouping/GetGroupByProcessId 401 (Unauthorized)
var headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("Accept", "application/json");
fetch("https://<host-name>/Grouping/api/Grouping/GetGroupByProcessId", {
method: "POST",
credentials: "include",
headers: headers,
body: JSON.stringify({ GroupingValue: groupingValue }) //groupingValue is just a JSON array
})
.then(res => res.json())
.then(data => console.log(data))
Examining the response and request headers in the console, I see the following, and everything looks fine to me.
I can't seem to figure out why I keep getting an unauthorized message.
My GET requests are going through just fine.
This answer suggests that you can send JSON with a post, but I have that header for Allow-Headers and it's still not working. Any help would be appreciated!