首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Adobe中的URLRequest

Adobe中的URLRequest
EN

Stack Overflow用户
提问于 2011-03-28 15:19:24
回答 1查看 5.7K关注 0票数 1

我试图在Adobe中制作一个简单的HTTP,下面的代码大致如下:

代码语言:javascript
复制
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;

--这会产生类似于:的东西

代码语言:javascript
复制
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

我真正想要的是:

代码语言:javascript
复制
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

任何人都知道我是如何删除像Accept-Encoding这样的字段,添加像"Via“这样的字段,并将连接设置为"close”。

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

谢谢菲尔

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-28 16:12:50

Flash不允许您通过ActionScript更改接受编码或通过标头。如果你试着这样做,你会收到这样的信息:

错误#2096: header接受-编码不能通过ActionScript设置.

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

代码语言:javascript
复制
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”上的requestSender:

代码语言:javascript
复制
requestSender.addEventListener(Event.COMPLETE, completeHandler); 

private function completeHandler(event:Event):void {
    // do something with requestSender.data (or URLLoader(event.target).data)
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5461162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档