开发者

HTTP headers with Android and php with Apache

开发者 https://www.devze.com 2023-03-05 02:17 出处:网络
I have an app that has a web and android components to it and I wish to identify each of them. For this I am explicitly setting the User-Agent in the HTTP headers to something specific to android. But

I have an app that has a web and android components to it and I wish to identify each of them. For this I am explicitly setting the User-Agent in the HTTP headers to something specific to android. But Apache is not passing the User-Agent to me. If I hit the same URL with the browser from the same machine I get a complete list of headers in the php code when I dump $_SERVER array including the HTTP_USER_AGENT. But I get nothing with the android client( except for SCRIPT_NAME and REQUEST_TIME). Does Apache filter stuff out?

I see that if I don't set the headers in the Java code nothing is passed. I use tcpdump and see the following as the User-Agent passed to the server.

User-Agent: Android app1.0\r\n

Any help is greatly appreciated.

EDIT: Here is the code I use to add the Use开发者_JAVA技巧r-Agent header in my Android app.

HttpPost postObj = null;

httpHost = new HttpHost(MyBaseURL);

postObj = new HttpPost(urlpath);

postObj.setHeader("User-Agent", "Android app1.0");

HttpResponse response = httpClient.execute(httpHost, postObj);

Thanks,

P


I just read a little bit about the spec on Wikipedia and the link that wikipedia provides to the actual RFC containing the definition of requirements for UA strings, and there seems to be a requirement that the product and version be separated by a slash. Check these out:

http://en.wikipedia.org/wiki/User_agent#Format

https://www.rfc-editor.org/rfc/rfc1945#section-3.7

Maybe Apache is deciding that your string is an invalid User-Agent string and not considering it. Try changing

Android app1.0

to

Android-app/1.0
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号