Tuesday, April 21, 2009

REQUEST HEADERS in FLEX using GET - POST Methods


We can modify Request Header in Flex under the certain circumstances only

var header:URLRequestHeader = new URLRequestHeader("newHeader", "newValue");
var request:URLRequest = new URLRequest("http://www.[vrathore.blogspot].com/");
request.data = new URLVariables("name=Varun+Rathore");
request.requestHeaders.push(header);

However, its possible to modify the headers on a POST request only.
request.method = URLRequestMethod.POST;

This should be taken care that we specifically give the request method as the Flash Player will convert POST requests into GET requests if the request is empty.

Other thing which should be kept in mind is to pass atleast one variable along with the request. Otherwise the headers will remain unchanged.
var variables:URLVariables = new URLVariables();
variables.name = "newValue";
request.data = variables;

Cheers
Varun Rathore

2 comments:

ElDalaiElDeLosTalones said...

Hi!
i'm testing my Flex app, change to POST method with URLVariables & i 'd get a GET!!

var urlRequest : URLRequest = new URLRequest("http://www.google.com");
urlRequest.method = URLRequestMethod.POST;


var urlVar: URLVariables = new URLVariables();


urlVar.clave2 = "";

urlRequest.data = urlVar;


navigateToURL(urlRequest);


Any Idea!
Thanks!!!!!!!!!!!!!!!!

vrathore said...

Use URLLoader to load the URLRequest as follows instead of using navigateToUrl function

UrLLoader.load(urlRequest);

I think it would solve your issue.

Regards
Varun

About Me