http协议的主要特点:
支持客户/服务模式;简单快速;灵活(允许任意数据类型的数据对象:Content-Type标识);无连接;无状态;
http URL:
URL是一种特殊类型的URI,包含了用于查找某个资源的足够的信息;格式:http://host:[":"port][abs_path]
工作浏览器帮助把空缺abs_path置为"/",譬如将www.mop.com自动转为www.mop.com/
http Request:
http请求分三部分:请求行、消息报头、请求正文;
请求行格式:Method Request-URI HTTP-Version CRLF 其中HTTP-Version表示http协议的版本号,
CRLF表示回车和换行;
请求方法:GET,POST,HEAD,PUT,DELETE,TRACE,CONNECT,OPTIONS
eg: 1)GET /form.html HTTP/1.1 (CRLF)
2)POST /reg.jsp HTTP/ (CRLF)
Accept:image/gif,image/x-xbit,...(CRLF)
.. HOST:www.sina.com.cn
Content-Length:22
Connection:Keep-Alive
Cache-Control:no-cache()
(CRLF) //表示消息报头已经结束,在此之前为消息报头;
user=jeffrey&pwd=23534...//以下为提交信息;
3)Head使用与get相同,但是响应只返回报头信息;
对应HttpClient中关键代码:
---------------------------------------------------
URI uri = URIUtils.createURI("http","www.google.com",-1,"/search","q=.&q1=");
HttpGet httpget = new HttpGet(uri);
or HttpGet httpget = new HttpGet(string uristring);
or List<NameValuePair> qparams = new ArrayList<NameValue
---------------------------------------------------