URLRequest/URLLoader auto-converting POST request to GET

前端 未结 2 1019
傲寒
傲寒 2020-12-21 01:12

When I execute the following code:

var urlRequest:URLRequest = new URLRequest(\"http://somehost/with/some/path?andsomequerystring=true\");
urlRequest.method          


        
相关标签:
2条回答
  • 2020-12-21 01:33

    It is because the way you are having your url. If you want to have your variables for POST method you need to use URLVariables.

    var urlRequest:URLRequest = new URLRequest(YOUR_REQUEST_URL_HERE);
    var variables:URLVariables = new URLVariables();
    variables.andsomequerystring = true;
    
    urlRequest.data = variables;
    urlRequest.method = 'POST';
    var urlLoader:URLLoader = new URLLoader(urlRequest);
    urlLoader.addEventListener(Event.COMPLETE,  function(event:Event):void{
        trace('sweet');
    });
    
    0 讨论(0)
  • 2020-12-21 01:41

    Ah think I found the answer, seems you have to specify a body as well or else it will still send as a GET request from their docs:

    Note: If running in Flash Player and the referenced form has no body, Flash Player automatically uses a GET operation, even if the method is set to URLRequestMethod.POST. For this reason, it is recommended to always include a "dummy" body to ensure that the correct method is used.

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#url

    0 讨论(0)
提交回复
热议问题