您的位置:首页 > 理论基础 > 计算机网络

我们从HTTP Server开始

2015-03-27 23:41 141 查看
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程序。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐