I use Azure API Management to provide a clean interface to third parties for integration purposes.
I want to do a POST with a JSON object to create this object in the backend. This works fine on the test console available on the portal site, but does not work when I try to make a simple client script from a web page:
$.ajax({ url: 'https://.azure-api.net/api/samplerequest/create?' + $.param(params), type: 'POST', data: JSON.stringify(sampleRequest), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data, par2, par3) { $("#txtResult").val(JSON.stringify(data)); } });
Setting the contentType header to "application / json" causes the browser to first make an OPTIONS call. My WebAPI project is configured to enable CORS, and I checked this. My WebAPI project returns the following headers for the OPTIONS method:
Access-Control-Allow-Head ... content-type Access-Control-Allow-Orig ... *
However, if I try to call this operation using the Azure Management API, I get a status of 200 for the OPTIONS method, but there are no other headers. I tried many configuration policies, this was my last attempt:
<policies> <inbound> <base /> <cors> <allowed-origins> <origin>*</origin> </allowed-origins> <allowed-methods> <method>POST</method> <method>OPTIONS</method> </allowed-methods> <allowed-headers> <header>contentType</header> </allowed-headers> </cors> </inbound> <outbound> <base /> </outbound> </policies>
What am I missing to make this work?
javascript azure-api-management
Frederik vellemans
source share