Android HTTP 用户代理
问题描述:
如何在http_user_agent 中获取真实设备?当我使用 WebView 时,我可以获得这样的真实值:
How do I get the real device in http_user_agent? When I use a WebView, I can get the real value like this:
[HTTP_USER_AGENT] => Mozilla/5.0(Linux; U; Android 2.2; en-gb; LG-P500 Build/FRF91)
AppleWebKit/533.0 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
但是当我使用 Apache 连接时,结果是不同的:
But when I use an Apache connection, the result is different:
[HTTP_USER_AGENT] => Apache-HttpClient/UNAVAILABLE(java 1.4).
有什么问题吗?
答
如果你不想为你创建的每个请求调用 setHeader()
你可以设置 http 客户端参数 CoreProtocolPNames.USER_AGENT
.做完这个HTTP客户端会自动把这个header参数添加到每个请求中.
If you don't want to call setHeader()
for every request you create you can set the http client parameter CoreProtocolPNames.USER_AGENT
. After doing this HTTP client will automatically add this header parameter to each request.
类似于:
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Custom user agent");
当您创建 HttpClient
时.