Issue with making a POST call to a REST service fr

2019-08-18 17:31发布

问题:

I'm working with a Jetty based REST service wrote by a 3rd party developer to which I have to make calls from actionscript 3. There are multiple calls available and most of them work, there only one I'm having trouble with: To end a session I have to make a POST request to http://localhost/control/end.

I've made a basic test with Simple Rest Client in Chrome and that works:

  1. I get a status 200 response
  2. In service's console I see a setEnd call made

The problem is, when I try the same in actionscript, it doesn't seem to work. Here's my basic call:

private function deleteSID(event : MouseEvent) : void {
            var request:URLRequest = new URLRequest(SERVER+"control/end"); 
            request.method = URLRequestMethod.POST;
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, deletedSID);
            loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
            loader.addEventListener(HTTPStatusEvent.HTTP_STATUS , onHTTPStatus);
            loader.load(request);
        }

But I get a 404 instead of a 200, as if it's not actually doing a POST.

Unfortunately I don't have a lot experience with REST APIs, so any hint/tip on what I might be missing is appreciated.

回答1:

Try sending some data with your POST call:

var requestVars:URLVariables = new URLVariables(); 
requestVars.dummy = "lol"; 
...
request.data = requestVars;