Skip to main content
Participant
October 23, 2013
Question

How does AIR handle CORS? Does the browser make OPTIONS requests (I am not seeing any)

  • October 23, 2013
  • 1 reply
  • 911 views

I have a desktop application which communicates from the local machine to a remote web service. The application uses the full range of REST requests, GET, POST, PUT, DELETE. DELETE calls fail when I test in app (rather than just running the app in a browser). When I inspect the web traffic I notice that the browser makes an OPTIONS call prior to the actual call. In AIR no OPTIONS call is made.

Any advice? I'd like to understand how to work with cross domain calls in a AIR Javascript application.

Thanks,

Scott

This topic has been closed for replies.

1 reply

Inspiring
October 23, 2013

I didn't think AIR apps had any CORS restrictions. They're not being run from inside a browser, where CORS would normally apply.

I've got desktop, iOS, and Android apps making calls to a remote server. The actionscript URLRequestMethod is always 'POST' though. I've never tried DELETE.

Do you get an Error '0'? I would interpret that as the request not reaching the server at all.

Nick

Participant
October 23, 2013

I have done some more tests. I think you are right. I don't see CORS options calls but all they don't seem to be required. As its a JS project I thought that the internal webkit browser might enforce this. So for the most part its all working.

What I am seeing now is a bit stranger. There is a default JSON payload that the server is expecting on all calls. In the case of my DELETE call this JSON payload has apparently been removed from the request, but only inside of AIR. The missing payload causes the server to respond with the 400. The very same code run through Chrome or Safari works fine.

Do you think that AIR is just removing the payload because its bad REST design?

The payload is empty in any case (I tried putting in placeholder data to see if that would stop if from getting removed and it did not work).

Inspiring
October 25, 2013

When you say JavaScript project, does that mean you are loading a web page in a stagewebview in an AIR app and making requests to the server from that?

I've handled CORS requests in javascript loaded in a browser, and i've handled stagewebview pages making javascript calls to a server in the same domain, but i've never tried both together.

If you've managed to do that and it's successfully handling everything except DELETE methods then that's a good result already IMO

Your issue might just be a quirk of the web layout engine used by stagewebview on whatever platform you're running it from (for example webkit). I often see different behaviours on desktop, ios and android.

Nick