您的位置:首页 > 理论基础 > 计算机网络

移动APP之HTTP协议

2013-11-26 23:08 435 查看
HTTP —— 超文本传输协议,也是移动互联网比较常用协议之一。是一种应用层协议,由请求和应答两部分构成,是典型的服务器客户端模型。比较常用的方法有POST,GET方法。

目前Java部分实现基本分两种方式,一种Java的JDK提供的HttpURLConnection,还有一种是Apache封装的开源框架HttpClient。相比较HttpClient由于是封装后的HTTP实现,所以比较适合快速开发上层应用。二者区别如下(借用网上别人的表格):

URLConnection

HTTPClient
代理和SOCKS
Full support in Netscape browser, appletviewer, and applications (SOCKS: Version 4 only); no additional limitations from security policies.
Full support (SOCKS: Version 4 and 5); limited in applets however by security policies; in Netscape can't pick up the settings from the browser.
授权
Full support for Basic Authorization in Netscape (can use info given by the user for normal accesses outside of the applet); no support in appletviewer or applications.
Full support everywhere; however cannot access previously given info from Netscape, thereby possibly requesting the user to enter info (s)he has already given for a previous access. Also, you can add/implement additional
authentication mechanisms yourself.
支持的方法
只支持GET和POST方法
Only has GET and POST.
Has HEAD, GET, POST, PUT, DELETE, TRACE and OPTIONS, 添加了一些额外的属性方法。
头部信息
Currently you can only set any request headers if you are doing a POST under Netscape; for GETs and the JDK you can't set any headers.

Under Netscape 3.0 you can read headers only if the resource was returned with a Content-length header; if no Content-length header was returned, or under previous versions of Netscape, or using the JDK no headers can be read.
Allows any arbitrary headers to be sent and received.
自动重定向处理
Yes.
Yes (as allowed by the HTTP/1.1 spec).
持久连接
No support currently in JDK; under Netscape uses HTTP/1.0 Keep-Alive's.
Supports HTTP/1.0 Keep-Alive's and HTTP/1.1 persistence.
Pipelining of Requests
No.
Yes.
可以处理HTTP之外的协议
理论上可以,然而当前仅仅实现了HTTP协议
不支持
可以做基于SSL的HTTP (https)
Under Netscape, yes. Using Appletviewer or in an application, no.
No (not yet).
Source code available
No.
Yes.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: