Android HTTP 用户代理 [英] Android HTTP User Agent
本文介绍了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
时.
这篇关于Android HTTP 用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文