HTTP

The HTTP protocol enables web servers and browsers to exchange data over the Internet

HTTP is connectionless - no connection is ever maintain.

HTTP is media independent - any type of file can be send, as long as client and server accept it.


vocab: CRLF - carriage return line feed


URL format

protocol://[host.]domain[:port][/context][/resource][?query string]

or

protocol://IP address[:port][/context][/resource][?query string]
 

HTTP request format

An HTTP request consists of three components:

images   Initial Line

images   Header Lines

images   Message Body

Initial Line 
Header1: value1
Header2: value2
Header3: value3

[Optional message body, the type of body is specified by Content-Type Header, for HTML file, the value is text/html]

Initial Lines

Initial line include method version

get

GET / HTTP/1.1

post( contain status code )

HTTP/1.0 200 OK or
HTTP/1.0 404 Not Found


Header Lines

contains information about the request or response
Format: 
"Header-Name: value", ending with CRLF

Message Body

If a message has body, there is usually a Content-Type header line to describe the mime type

Example

A typical HTTP get example notice there is no  message body in this GET request

GET / HTTP/1.1
Host: www.ifeng.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: ALLYESID4=03BC203464090910; userid=1324935855700_3249; vjuids=36521e1c9.1347c54c390.0.7c3f30c6947c48; vjlast=1324935857.1344027154.11; samemappingcookie=m; py_map=1; ua_map=adchina; _plst[_plid_]=3536482416; weather_city=bj; Q37_visitedfid=144; pgv_pvi=4805773312; olyput=1344006725549%7C1344027257398
If-Modified-Since: Fri, 03 Aug 2012 20:50:57 GMT


A typical HTTP response from server, There is no message body in this response.  The response type is specified by Content-Type. If a web page is sent, then the content-type should be text/html

HTTP/1.1 200 OK
Date: Sun, 10 Oct 2010 23:26:07 GMT
Server: Apache/2.2.8 (Ubuntu) mod_ssl/2.2.8 OpenSSL/0.9.8g
Last-Modified: Sun, 26 Sep 2010 22:04:35 GMT
ETag: "45b6-834-49130cc1182c0"
Accept-Ranges: bytes
Content-Length: 13
Connection: close
Content-Type: text/html

Hello world!

Reference:

http://www.tutorialspoint.com/http/index.htm
http://en.wikipedia.org/wiki/HTTP_body_data



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值