The Hypertext Transfer Protocol(HTTP)
2010-12-03 23:06
211 查看
Excerpted from .
HTTP Requests:
A HTTP request consists of three components:
Method-Uniform Resource Identifier(URI)-Protocol/Version
Request headers
Entity body
An example of a HTTP request is the following:
GET /index.html HTTP/1.1
Accept: */*
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: localhost:8080
Connection: Keep-Alive
The method-URI-protocol version apprears as the first line of the request.
GET /index.html HTTP/1.1
Where GET is the request method, /index.html represents the URI and HTTP/1.1 is the Protocol/Version section.
Each HTTP request can use one of the many request methods as specified in the HTTP standards. The HTTP 1.1 supports seven types of request: GET, POST, HEAD, OPTIONS, PUT, DELETE and TRACE. GET and POST are the most commonly used in Internet application.
The URI specifies an Internet resource completely. A URI is usually interpreted as being relative to the server's root directory. Thus, it should always begin with a forward slash /. A Uniform Resource Location(URL) is actually a type of URI. The protocol version represents the version of the HTTP protocol being used.
The request header comtains useful information about the client environment and the entity body of the request. For example, it could contain the language the browser is set for, the length of th entiry body, and so on. Each header is separated by a carriage return/linefeed(CRLF) sequence.
Between the headers and the entity body, there is a blank line(CRLF) that is important to the HTTP request format. The CRLF tell the HTTP server where the entiry body begins. In some Internet programming books, this CRLF is considered the fourth component of an HTTP request.
HTTP Response
Similar to a HTTP request, an HTTP response also consists of three parts:
Protocol-Status code-Description
Response headers
Entiry body
The following is an example of a HTTP response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Mon, 5 Jan 2004 13:13:33 GMT
Content-Type: text/html
Last-Modified: Mon, 5 Jan 2004 13:13:12 GMT
Content-Length: 112
<html>
<head>
<title>HTTP Response
Example</title>
</head>
<body>
Welcome to Brainy
Software
</body>
</html>
The first line of the response header is similar to the first line of the request header. The first line tells you that protocol used is HTTP version 1.1, the request succeeded(200=success), and that everything went okay.
The response headers contain useful information similar to the haeders in the request.
HTTP Requests:
A HTTP request consists of three components:
Method-Uniform Resource Identifier(URI)-Protocol/Version
Request headers
Entity body
An example of a HTTP request is the following:
GET /index.html HTTP/1.1
Accept: */*
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: localhost:8080
Connection: Keep-Alive
The method-URI-protocol version apprears as the first line of the request.
GET /index.html HTTP/1.1
Where GET is the request method, /index.html represents the URI and HTTP/1.1 is the Protocol/Version section.
Each HTTP request can use one of the many request methods as specified in the HTTP standards. The HTTP 1.1 supports seven types of request: GET, POST, HEAD, OPTIONS, PUT, DELETE and TRACE. GET and POST are the most commonly used in Internet application.
The URI specifies an Internet resource completely. A URI is usually interpreted as being relative to the server's root directory. Thus, it should always begin with a forward slash /. A Uniform Resource Location(URL) is actually a type of URI. The protocol version represents the version of the HTTP protocol being used.
The request header comtains useful information about the client environment and the entity body of the request. For example, it could contain the language the browser is set for, the length of th entiry body, and so on. Each header is separated by a carriage return/linefeed(CRLF) sequence.
Between the headers and the entity body, there is a blank line(CRLF) that is important to the HTTP request format. The CRLF tell the HTTP server where the entiry body begins. In some Internet programming books, this CRLF is considered the fourth component of an HTTP request.
HTTP Response
Similar to a HTTP request, an HTTP response also consists of three parts:
Protocol-Status code-Description
Response headers
Entiry body
The following is an example of a HTTP response:
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Mon, 5 Jan 2004 13:13:33 GMT
Content-Type: text/html
Last-Modified: Mon, 5 Jan 2004 13:13:12 GMT
Content-Length: 112
<html>
<head>
<title>HTTP Response
Example</title>
</head>
<body>
Welcome to Brainy
Software
</body>
</html>
The first line of the response header is similar to the first line of the request header. The first line tells you that protocol used is HTTP version 1.1, the request succeeded(200=success), and that everything went okay.
The response headers contain useful information similar to the haeders in the request.
相关文章推荐
- HTTP(HyperTextTransferProtocol)即超文本传输协议
- Hypertext Transfer Protocol -- HTTP/1.1
- HTTP-Hypertext Transfer Protocol超文本传输协议
- HTTP深入浅出 http请求HTTP(HyperText Transfer Protocol)是一套计算机通过网络进行通信的规则。计算机专家设计出HTTP,使HTTP客户(如Web浏览器)能够从HT
- Hypertext Transfer Protocol -- HTTP/1.1
- 简析超文本传输协议(HTTP,HyperText Transfer Protocol)
- HTTP(HyperText Transfer Protocol) 01-基础
- HTTP(HyperText Transfer Protocol) 01-基础
- Status Code Definitions --Hypertext Transfer Protocol -- HTTP/1.1
- Hypertext Transfer Protocol -- HTTP/1.1 specification
- HTTP(HyperText Transfer Protocol) 02-HTTP代理
- HTTP(HyperText Transfer Protocol) 02-HTTP代理
- RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
- Hypertext Transfer Protocol -- HTTP/1.1
- Hypertext Transfer Protocol -- HTTP/1.1 Status Code(HTTP 响应状态代码)
- Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
- HTTP, HyperText Transfer Protocol
- Hypertext Transfer Protocol -- HTTP/1.0
- HTTP协议——HyperText Transfer Protocol(超文本传输协议)
- Hypertext Transfer Protocol -- HTTP/1.0