Iphone xhr.setRequestHeader User Agent Override Error
I was trying to change the User-Agent see the code below… But still the default user-agent is showing in the server log.
Please help me to figure out the exact command to send a user define user-agent.
125.xx.xx.12 www.xxx.com - [14/May/2010:12:53:09 +0400] "GET / HTTP/1.1" 200 18520 "-" "Appcelerator Titanium/1.2.0 (iPhone Simulator/3.1.2; iPhone OS; en_US;)"
125.xx.xx.12 www.xxx.com - [14/May/2010:12:53:09 +0400] "GET / HTTP/1.1" 200 18520 "-" "Appcelerator Titanium/1.2.0 (iPhone Simulator/3.1.2; iPhone OS; en_US;)"
125.xx.xx.12 www.xxx.com - [14/May/2010:12:53:09 +0400] "GET / HTTP/1.1" 200 18520 "-" "Appcelerator Titanium/1.2.0 (iPhone Simulator/3.1.2; iPhone OS; en_US;)"
var c = Titanium.Network.createHTTPClient();
c.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)");
c.setTimeout(10000);
c.onload = function()
{
alert(this.responseText);
};
c.error = function(e)
{
Ti.UI.createAlertDialog({title:'Image Search', message:'Error: ' + e.error}).show();
};
c.open('POST', url);
c.send();
1 Answer
-
setting the request header should be after open and before send.