我试图在Adobe中制作一个简单的HTTP,下面的代码大致如下:
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任何人都知道我是如何删除像Accept-Encoding这样的字段,添加像"Via“这样的字段,并将连接设置为"close”。
另外,我们如何从HTTP请求中获得响应?
谢谢菲尔
发布于 2011-03-28 16:12:50
Flash不允许您通过ActionScript更改接受编码或通过标头。如果你试着这样做,你会收到这样的信息:
错误#2096: header接受-编码不能通过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;要获得响应,您必须侦听“requestSender”上的requestSender:
requestSender.addEventListener(Event.COMPLETE, completeHandler);
private function completeHandler(event:Event):void {
// do something with requestSender.data (or URLLoader(event.target).data)
}https://stackoverflow.com/questions/5461162
复制相似问题