URLRequest/URLLoader 自动将 POST 请求转换为 GET [英] URLRequest/URLLoader auto-converting POST request to GET

查看:29
本文介绍了URLRequest/URLLoader 自动将 POST 请求转换为 GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行以下代码时:

var urlRequest:URLRequest = new URLRequest("http://somehost/with/some/path?andsomequerystring=true");
urlRequest.method = 'POST';
var urlLoader:URLLoader = new URLLoader(urlRequest);
urlLoader.addEventListener(Event.COMPLETE,  function(event:Event):void{
    trace('sweet');
});

由于查询字符串的存在,它将我的显式 POST 请求转换为 GET.如果我删除查询字符串(并将其序列化为 POST 正文的一部分),它会成功发出相应的 POST 请求.有什么办法可以防止它这样做吗?我的服务器要求使用查询字符串发出 POST 请求.

It turns my explicit POST request to GET due to the presence of the querystring. If I remove the querystring (and serialize as part of the POST body), it successfully makes the corresponding POST request. Is there any way to prevent it from doing that? My server requires that a POST request be made with a querystring.

推荐答案

啊,我想我找到了答案,看来您还必须指定一个正文,否则它仍会作为来自他们文档的 GET 请求发送:

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:

注意:如果在 Flash Player 中运行并且引用的表单没有正文,Flash Player 自动使用 GET 操作,即使该方法是设置为 URLRequestMethod.POST.为此,建议始终包含一个虚拟"主体,以确保正确的方法是用过.

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

这篇关于URLRequest/URLLoader 自动将 POST 请求转换为 GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆