Reputation: 2791
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
Upvotes: 1
Views: 5781
Reputation: 26880
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)
}
Upvotes: 1