Adobe Flex 中的 HTTP URLRequest

发布于 2024-10-28 07:08:52 字数 1087 浏览 3 评论 0原文

我正在尝试在 Adob​​e Flex 中创建一个简单的 HTTP URLReqest,大致代码如下:

var requestSender:URLLoader = new URLLoader();
var urlRequest :URLRequest = new URLRequest("http://localhost:8888");
var msg:String = "data=blah";

urlRequest.data = msg;
urlRequest.contentType = "application/x-www-form-urlencoded";
urlRequest.method = URLRequestMethod.POST;

这会产生接近于:

POST / HTTP/1.1
Referer: app:/PersonSearch.swf
Accept: text/xml, application/xml, application/xhtml+xml, ...
x-flash-version: 10,1,85,3
Content-Type: application/x-www-form-urlencoded
Content-Length: 102
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (Windows; U; en-US) ...
Host: 127.0.0.1:8888
Connection: Keep-Alive

data=blah

我真正想要的是:

POST / HTTP/1.1
Content-Type:application/x-www-form-urlencoded
Connection:close
Via:MDS_777
Accept:*/ *
Host:localhost:8888
Content-Length:104

data=blah

任何人都知道我如何删除字段例如接受编码,添加“Via”等字段并将连接设置为“关闭”

另外,我们如何从 HTTP 请求中获取响应?

谢谢 菲尔

Im trying to make a simple HTTP URLReqest in Adobe Flex, heres the code roughly:

var requestSender:URLLoader = new URLLoader();
var urlRequest :URLRequest = new URLRequest("http://localhost:8888");
var msg:String = "data=blah";

urlRequest.data = msg;
urlRequest.contentType = "application/x-www-form-urlencoded";
urlRequest.method = URLRequestMethod.POST;

This produces something close to:

POST / HTTP/1.1
Referer: app:/PersonSearch.swf
Accept: text/xml, application/xml, application/xhtml+xml, ...
x-flash-version: 10,1,85,3
Content-Type: application/x-www-form-urlencoded
Content-Length: 102
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (Windows; U; en-US) ...
Host: 127.0.0.1:8888
Connection: Keep-Alive

data=blah

What I really want is:

POST / HTTP/1.1
Content-Type:application/x-www-form-urlencoded
Connection:close
Via:MDS_777
Accept:*/ *
Host:localhost:8888
Content-Length:104

data=blah

Anyone know how I remove the fields like Accept-Encoding, add fields like "Via" and set Connection to "close"?

Also how do we get the responce from the HTTP request?

Thanks
Phil

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫雪独思 2024-11-04 07:08:52

Flash Player 不允许您通过 ActionScript 更改 Accept-EncodingVia 标头。如果您尝试这样做,您将收到如下消息:

错误#2096:HTTP 请求标头
接受编码不能通过设置
动作脚本。

如果您使用 URL 变量,您可以尝试通过执行以下操作来简化代码:

var variables:URLVariables = new URLVariables();
variables.data = "blah"; //same as doing data=blah
variables.data2 = "blah2"; //same as doing data2=blah2

var requestSender:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest("http://localhost:8888");
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;

要获取响应,您必须侦听“requestSender”上的 Event.COMPLETE

requestSender.addEventListener(Event.COMPLETE, completeHandler); 

private function completeHandler(event:Event):void {
    // do something with requestSender.data (or URLLoader(event.target).data)
}

The Flash Player doesn't allow you to change the Accept-Encoding or Via headers through ActionScript. If you try do that you will get a message like this one:

Error #2096: The HTTP request header
Accept-Encoding cannot be set via
ActionScript.

If you are using URL variables you can try to simplify your code by doing this:

var variables:URLVariables = new URLVariables();
variables.data = "blah"; //same as doing data=blah
variables.data2 = "blah2"; //same as doing data2=blah2

var requestSender:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest("http://localhost:8888");
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = variables;

To get the response you will have to listen for the Event.COMPLETE on the "requestSender":

requestSender.addEventListener(Event.COMPLETE, completeHandler); 

private function completeHandler(event:Event):void {
    // do something with requestSender.data (or URLLoader(event.target).data)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文