Hi @Akshay Bahir
Greetings! Welcome to Microsoft Q&A Forum. Thanks for posting you query here!
As per the error message, it indicates that the API you're trying to access does not include the Access-Control-Allow-Origin
header in its response. It means that the server (your Azure Function) is not configured to allow requests from the origin of your web app.
To fix this problem, make sure CORS is set up correctly on your Azure Function. You need to ensure that the Azure Function is configured to allow cross-origin requests from your web application. Here are the steps to do it:
- Configuration for your Azure function is done correctly from your Web app's origin.
- Make sure your Azure Function code includes the necessary CORS headers in the response.
In the Function code make sure you Set the allowed Origins and Set the allow HTTP methods as well as Set the allowed request headers.
AllowAnyHeader
affects preflight request and the Access-Control-Request-Headers header. To allow specific headers to be sent in a CORS request, called author request headers, call WithHeaders and specify the allowed headers. specify the allowed headers.
If the preflight request is denied, the app returns a 200 OK
response but doesn't set the CORS headers. Therefore, the browser doesn't attempt the cross-origin request.
The browser can skip the preflight request if all the following conditions are true:
- The request method is GET, HEAD, or POST.
- The app doesn't set request headers other than
Accept
,Accept-Language
,Content-Language
,Content-Type
, orLast-Event-ID
. - The
Content-Type
header, if set, has one of the following values: -
application/x-www-form-urlencoded
-
multipart/form-data
-
text/plain
-
If you are using a different language or framework for your Azure Function, make sure to add the appropriate headers in the response.
Hope the issue will be resolved by following the above linked documents by using the appropriate headers
Please feel free to contact if the issue persists, we will be glad to assist you closely. Please do consider to click on "Accept Answer"
and "Up-vote"
on the post that helps you, as it can be beneficial to other community members.