Issue with making a POST call to a REST service from as3

喜你入骨 提交于 2020-01-06 20:23:47

问题


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; 


来源:https://stackoverflow.com/questions/10262149/issue-with-making-a-post-call-to-a-rest-service-from-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!