Android的HTTP用户代理 [英] Android HTTP User Agent

查看:211
本文介绍了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).

这是什么问题?

What's the problem?

推荐答案

如果你不想叫 SetHeader可以()为每个请求创建可以设置HTTP客户端参数 CoreProtocolPNames.USER_AGENT 。这样做HTTP客户端后,将这个头参数自动添加到每个请求。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆