Android 的 HTTP 标头和 Apache 的 php
我有一个应用程序,其中包含网络和 Android 组件,我希望识别它们中的每一个。为此,我将 HTTP 标头中的 User-Agent 显式设置为特定于 android 的内容。但 Apache 没有将用户代理传递给我。如果我使用同一台机器上的浏览器点击相同的 URL,当我转储 $_SERVER 数组(包括 HTTP_USER_AGENT)时,我会在 php 代码中获得完整的标头列表。但我在 Android 客户端上什么也没得到(除了 SCRIPT_NAME 和 REQUEST_TIME)。 Apache 会过滤掉一些东西吗?
我发现如果我不在 Java 代码中设置标头,则不会传递任何内容。我使用 tcpdump 并看到以下内容作为传递到服务器的用户代理。
User-Agent: Android app1.0\r\n
非常感谢任何帮助。
编辑:这是我用来在 Android 应用程序中添加 User-Agent 标头的代码。
HttpPost postObj = null;
httpHost = new HttpHost(MyBaseURL);
postObj = new HttpPost(urlpath);
postObj.setHeader("User-Agent", "Android app1.0");
HttpResponse response = httpClient.execute(httpHost, postObj);
谢谢,
P
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 User-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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚阅读了一些关于 Wikipedia 上的规范以及 Wikipedia 提供的包含 UA 字符串要求定义的实际 RFC 的链接,并且似乎要求产品和版本用斜杠分隔。查看这些:
http://en.wikipedia.org/wiki/User_agent#Format
https://www.rfc-editor.org/rfc/rfc1945#section-3.7
也许 Apache 认为您的字符串是无效的用户代理字符串,并且不考虑它。尝试更改
为
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
to