My HTTP Post calls work as expected from my UWP and Droid projects but when I make the same call from my WASM project Azure Functions sees the call as OPTIONS and not POST. I read it's a CORS issue and I needed to add a local.settings.json file to my Azure Functions project. It now looks like this:
{
"Values": {
},
"Host": {
"CORS": "*"
}
}
I still experience the same issue. It's not the HTTP call since it works from the other platforms in UNO.
Anyone know what's going on?
That's the magic of the CORS mecanism. This call is called a CORS preflight and it's used to check with the server if the call is authorized by the server.
Since WebAssembly (WASM) applications are running inside a browser, they can't escape all the security systems present in a browser. Http calls are actually done by browsers using the fetch
api by the WasmHttpHandler
.
Most of the time, this happened when you are making calls on a different hostname that your application. Let's say you deploy your Wasm application on https://mybikeisyellow.app/
and doing REST calls to https://myneightborbikeisred.biz
, the browser will first make an OPTIONS
call to https://myneightborbikeisred.biz
before allowing any other non-GET
call to be made there.
You can search on the Internet about CORS, there's plenty of very useful information on why it's there and how to manage it. I found this one pretty well done.
For your specific problem in Azure Fuctions, follow this guide and you'll be able to make it accept your requests.