seannell

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

web server接收HTTP请求,并返回HTTP响应。

HTTP请求

HTTP请求由三部分组成 :

  • Method—Uniform Resource Identifier (URI)—Protocol/Version
  • Request headers
  • Blank line(一个空行)
  • Entity body

以下是一个最常见的HTTP请求

method—URI—protocol
HTTP标准中定义了7种请求方法:GET/POST/HEAD/OPTIONS/PUT/DELETE/TRACE

POST /examples/default.jsp HTTP/1.1
Accept: text/plain; text/html
Accept-Language: en-gb
Connection: Keep-Alive
Host: localhost
User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
Content-Length: 33
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate

lastName=Franks&firstName=Michael

HTTP响应

与请求相对应,响应也由三部分组成:

  • Protocol—Status code—Description
  • Response headers
  • Blank line(一个空行)
  • Entity body

以下是一个典型的http响应

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>

下一篇将实现一个可以发送和接收请求的HTTP Server程序。

posted on 2015-03-27 23:41  seannell  阅读(137)  评论(0编辑  收藏  举报