I'm using Azure API management which internally access my python Flask web service. Azure API works good for GET operations. For POST, when I make jquery AJAX call, the request is converted into OPTIONS and the following error shows up
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://domain.com' is therefore not allowed access. The response had HTTP status code 500.
I have added the following policy for the Azure API,
<policies>
<inbound>
<cors>
<allowed-origins>
<origin>*</origin>
</allowed-origins>
<allowed-methods>
<method>*</method>
</allowed-methods>
<allowed-headers>
<header>*</header>
</allowed-headers>
</cors>
<base />
</inbound>
<outbound>
<base />
</outbound>
</policies>
But still I'm facing the same issue.
The same error showed up when I directly make AJAX POST request to my python flask service and I fixed it by adding the following code in the flask,
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
What should I change in Azure API management to get the POST operation working??