2011-03-28 66 views
1

林试图在Adobe Flex的一个简单的HTTP URLReqest,继承人的代码大致为:HTTP的URLRequest在Adobe的Flex

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请求获取响应?

感谢 菲尔

+0

你试图解决我这样做的问题是什么? – 2011-03-28 16:18:47

回答

1

Flash播放器不允许你改变接受编码通过通过ActionScript头。如果试图这样做,你会得到这样的消息:

错误#2096:HTTP请求头 的Accept-Encoding无法通过 ActionScript中设置。

如果您使用的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; 

获得响应,你将不得不监听Event.COMPLETE的“requestSender”:

requestSender.addEventListener(Event.COMPLETE, completeHandler); 

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