开发手册 欢迎您!
软件开发者资料库

HTTP - 消息示例

HTTP消息示例 - 从简单的概述,协议参数,消息体系结构,请求,响应,连接,缓存,状态代码,标头字段,安全性开始,从简单而简单的步骤学习HTTP协议(超文本,传输,基于RFC 2616的协议)和GET,POST,HEAD,PUT等方法以及合适的例子。

示例1

it1352.com 上运行的Web服务器获取 hello.htm 页面的HTTP请求.

客户请求

GET /hello.htm HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.IT屋.comAccept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alive

服务器响应

HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Last-Modified: Wed, 22 Jul 2009 19:15:56 GMTContent-Length: 88Content-Type: text/htmlConnection: Closed

      

Hello, World!

   

示例2

获取不存在的 t.html 页面的HTTP请求在 it1352.com 上运行的Web服务器上.

客户请求

GET /t.html HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.IT屋.comAccept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alive

Server回复

HTTP/1.1 404 Not FoundDate: Sun, 18 Oct 2012 10:36:20 GMTServer: Apache/2.2.14 (Win32)Content-Length: 230Content-Type: text/html; charset=iso-8859-1Connection: Closed

   404 Not Found   

Not Found

   

The requested URL /t.html was not found on this server.

示例3

从Web服务器获取 hello.htm 页面的HTTP请求在 it1352.com 上运行,但请求的HTTP版本不正确:

客户请求

GET /hello.htm HTTP1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.it1352.comAccept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alive

服务器响应

HTTP/1.1 400 Bad RequestDate: Sun, 18 Oct 2012 10:36:20 GMTServer: Apache/2.2.14 (Win32)Content-Length: 230Content-Type: text/html; charset=iso-8859-1Connection: Closed

   400 Bad Request   

Bad Request

   

Your browser sent a request that this server could not understand.

   

The request line contained invalid characters following the protocol string.

示例4

将表单数据发布到 process.cgi CGI页面的HTTP请求在 it1352.com 上运行的Web服务器上.服务器在将它们设置为cookie后返回传递的名称:

客户端请求

POST /cgi-bin/process.cgi HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.it1352.comContent-Type: text/xml; charset=utf-8Content-Length: 60Accept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alivefirst=Zara&last=Ali

服务器响应

HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Content-Length: 88Set-Cookie: first=Zara,last=Ali;domain=it1352.com;Expires=Mon, 19-Nov-2010 04:38:14 GMT;Path=/Content-Type: text/htmlConnection: Closed

   

Hello Zara Ali