from :
http://www.developershome.com/wap/wcss/wcss_tutorial.asp?page=toDiffUserAgents2
Before
we move on to discuss how to detect user agents, let's first have a
look at the steps involved in a typical request-response cycle
between a server and a client browser:
-
The
WAP browser requests an XHTML MP page from the server.
-
The
server receives the request and delivers the XHTML MP document to
the WAP browser.
-
The
WAP browser receives the XHTML MP document and finds that it
contains a <link> tag that references to an external cascading
style sheet.
-
The
WAP browser sends another request to the server in order to obtain
the WAP CSS cascading style sheet.
-
The
server receives the request and delivers the WAP CSS cascading style
sheet to the WAP browser.
-
The
WAP browser receives the WAP CSS file and displays the XHTML MP page
according to the style information contained in the WAP CSS file.
-
The
steps repeat when the user selects an anchor link or types a new URL
in the WAP browser.
As
you can see from above, the only thing that the server receives from
the client is the HTTP request. So, to determine the client's user
agent, the server needs to rely on the information included in the
HTTP request. Below shows a HTTP request example. It is a HTTP
request generated by the Nokia 6230 emulator (some headers that are
irrelevant to user agent detection are omitted).
GET
/example.xhtml HTTP/1.1
...
x-wap-profile:
"http://nds1.nds.nokia.com/uaprof/N6230r200.xml"
User-Agent:
Nokia6230/2.0 (03.14) Profile/MIDP-2.0 Configuration/CLDC-1.1
...
Both
the profile header and the user-agent header can be used for user
agent detection.
The
profile header holds the URL to the UAProf (User Agent Profile)
document of the wireless device. The UAProf document contains
information about the wireless device's characteristics and
capabilities such as screen size, character sets supported, number of
softkeys supported, etc. The details of the profile header and the
UAProf document is out of the scope of this section and it will be
covered in a future article.
The
user-agent header includes information like the wireless device's
name, platform, Java capabilities, etc. The format of the user-agent
header value is different for different brands of browsers. For
example, the user-agent header format generated by Nokia mobile phone
browsers are different from that generated by Sony Ericsson mobile
phone browsers. Here is a user-agent header generated by Sony
Ericsson Z1010:
User-Agent:
SonyEricssonZ1010/R1A SEMC-Browser/4.0
Note
that the user-agent header format may also vary among browsers of the
same brand, although the variations are usually small.
Below
is the user-agent header found in a HTTP request generated by
Microsoft Internet Explorer 6 on Windows 2000:
User-Agent:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
As
a general rule, you should find the brand name of a mobile phone in
its user-agent header value. For example, you should find the brand
name "Nokia" in the user-agent header generated by a Nokia
mobile phone, and you should find the brand name "SonyEricsson"
in the user-agent header generated by a Sony Ericsson mobile phone.
If
you find the word "Mozilla" in the user-agent header value,
then the client browser should be a desktop web browser like Mozilla
and Microsoft Internet Explorer. (Note that we have simplified things
a bit here. Actually, the existence of the word "Mozilla"
in the user-agent header value only indicates that it is very likely
that the user agent is a desktop web browser, but does not mean it
must be a desktop web browser. For example, some Nokia Series 60
mobile phones include the word "Mozilla" in their
user-agent header to indicate that they are web-capable. However,
note that the brand name "Nokia" is still present in their
user-agent header value.)
To
read the value of a HTTP header, you need to use a server-side
technology like ASP, Java Servlet, JSP, Perl, PHP, etc.
For
example, to read the user-agent header value and store it into a
variable uaheader
with JSP, use the following code:
String
uaheader = request.getHeader("user-agent");
For
ASP (VBScript), use the following code to read the user-agent header
value:
dim
uaheader
uaheader = Request.ServerVariables("http_user_agent")
For
ASP (JScript), use the following code to read the user-agent header
value:
var
uaheader = Request.ServerVariables("http_user_agent");
For
PHP, use the following code to read the user-agent header value:
$uaheader
= $_SERVER["HTTP_USER_AGENT"];
分享到:
相关推荐
有些时候我们需要判断此次请求来自手机还是电脑端,这个可以帮您解决
判断请求来源是电脑端还是移动端,有助于分类编程!
java判断PC端,Andiro,IOS,java判断PC端,Andiro,IOS,java判断PC端,Andiro,IOS,java判断PC端,Andiro,IOS
文件上传下载及消息传输,适合在手机和pc间上传下载文件及字符串消息(url)。手机和pc连同一个WiFi即可在一个网段内(ipconfig获取局域网内ip地址,192.168.*.*) 有的手机浏览器有权限设置问题,如小米浏览器上传文件...
在服务器端判断request来自Ajax请求(异步)还是传统请求(同步)
要想让网站适配PC和手机设备,首先要能做出准确的判断。HTTP请求的Header中的User-Agent可以区分客户端的浏览器类型,可以通过User-Agent来判断客户端的设备。
主要介绍了C#实现发送简单HTTP请求的方法,涉及C#操作http的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
httppost可以模拟post发送和get方法向目标网站提交请求,这个是电脑端的软件,不是运行于web的脚本代码 1. testhttppost.exe:http post上传文件工具; 2. TestHttpPost: 源码; 3.lr_post.txt: 录制的loadrunner ...
C++实现HTTP POST GET请求
c# rest http请求类库c# rest http请求类库c# rest http请求类库
C语言实现的HTTP请求,重写Http协议,并发送http报送的源文件
常用参考表对照表常用参考表对照表:FFB请求方法大全 Uaap/$$aooYs.WO*1.nRa$aNOYR$UaapM_RqbRsaMZRaUoQ):FFB请
httpwatch可以用来查看http协议请求状况,学习http协议或者判断http网络请求故障。本人用该软件检查过一个dns故障。
Nginx中http请求处理过程 有不少地方不是很明白 ,还望大家共同交流
c# http请求模拟
VB发送HTTP请求,返回网络请求的结果,内部还包含网络中各种制式转换的代码。
基于Linux平台下的Http请求,包括Http get请求和Http post请求,C++编写
压缩包里包含http和https两种请求,第一个文件是http请求包含post和get两种方式,剩下的是https的请求,最后一个文件里包含https的post和get两种方式。中间的两个是post 和 get 分开写的,按照需要引用吧
使用java的UrlConnection实现的简单的HTTP请求。
最近在工作中,由于合作商只提供uRL,我这边需要通过HTTP请求Get或Post方式请求Json数据,然后解析JSON格式,解析json我使用的第三方库rapidjson。开发环境是64位win7,VS2015。