原文地址:HTTP Developer’s Handbook 中文翻译 Chapter 5:第一节 HTTP请求的语法
一个Http请求(即由Web客户端发往Web服务器的消息),由以下3部分组成:
- Request line (请求行)
- HTTP headers (HTTP消息头,以下会简称消息头)
- Content (消息正文)
HTTP请求的第一行总是请求行(request line),请求行指定了请求方法(request method),资源的位置以及使用的HTTP协议的版本。这3个部分之间用空格隔开。例如:
这个例子指定了GET方法,位于/(文档根目录)下的资源以及 HTTP/1.1 版本的协议。
HTTP请求的第二个部分是 HTTP消息头(HTTP headers) 。 消息头包含了那些可以更清楚地解释Web客户端的请求的信息。可以出现在HTTP请求中的消息头有3种类型:
- General headers (通用的消息头)
- Request headers (请求头,与请求控制相关的头部)
- Entity headers (实体头,与消息正文相关的头部)
没有规定要求消息头遵循上述顺序。因为实体头是与消息正文相关的头部,所以较少在请求中出现。
Note
大多数HTTP请求不包含任何正文内容,因为他们的目的通常就是去请求一些内容。然而你将会看到,允许在请求中发送正文内容这种灵活性是非常有用的。尤其是对于需要交互的网站来说,为了交互需要,用户必须能够发送一些数据。
这里有一个例子,是作者在Chapter 3中使用他的Galeon 1.2.0浏览器在google中搜索HTTP时,浏览器向google的服务器发送的请求。
1 |
GET /search?hl=en&q=HTTP&btnG=Google+Search HTTP/1.1 |
3 |
User-Agent: Mozilla/5.0 Galeon/1.2.0 (X11; Linux i686; U;) Gecko/20020326 |
4 |
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9, |
5 |
text/plain;q=0.8, video/x-mng,image/png,image/jpeg,image/gif;q=0.2,
|
8 |
Accept-Encoding: gzip, deflate, compress;q=0.9 |
9 |
Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 |
11 |
Connection: keep-alive |
拆解来看,以下是该请求的请求行:
1 |
GET /search?hl=en&q=HTTP&btnG=Google+Search HTTP/1.1 |
请求方法GET, 资源 /search?hl=en&q=HTTP&btnG=Google+Search (一个相对 URL)以及HTTP版本 HTTP/1.1 被空格分隔。此例中,这个URL比 ‘/’ 这个字符包含了更多的关于所请求的资源的附加信息。关键词HTTP被包含在URL中是由于Google的<form>标签使用了GET方法。而使用POST方法会将所需的数据作为HTTP请求的正文来发送。Web开发的新手经常会将这2种方法搞混,关于这2种方法的区别将会在下一节“Request Methods(请求方法)”中更清楚的阐释。
该请求余下的部分就都是消息头了(因为是GET方法所以没有正文内容),按类型来分,以下是通用头部(General headers):
以下是 请求头部(Request headers):
2 |
User-Agent: Mozilla/5.0 Galeon/1.2.0 (X11; Linux i686; U;) Gecko/20020326 |
3 |
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9, |
4 |
text/plain;q=0.8, video/x-mng,image/png,image/jpeg,image/gif;q=0.2,
|
7 |
Accept-Encoding: gzip, deflate, compress;q=0.9 |
8 |
Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 |
一般来讲是非常容易区分一个头部是属于哪一类的。请求头会指定一些针对HTTP请求的信息,比如User-Agent头部是用来识别Web客户端软件的。通用头部是既能够用于HTTP请求又能够用于HTTP响应的。实体头部则是反应消息正文特征的一些信息。因为本例中的请求没有消息正文,所以它也没有实体头部。
请记住这个HTTP请求,因为它被用于本章的大多数例子。
本博客文章由LiZn创作或分享,以创作公用CC 姓名标示-非商业性-相同方式分享 3.0 Unported 授权条款共享。
转载请注明 转自: HTTP Developer’s Handbook 中文翻译 Chapter 5:第一节 HTTP请求的语法
分享到:
相关推荐
HTTP Developer's Handbook.doc ,这个是DOC版本 其他还有很多好东西,点击我的用户名查看
The HTTP Developer's Handbook is written specifically for Web developers. It begins by introducing the protocol and explaining it in a straightforward manner. It then illustrates how to leverage this ...
Python Developer's Handbook André Dos Santos Lessa Publisher: Sams Publishing
HTTP Developer's Handbook.chm 关于 http,很好的
压缩包包含3个文件 HTTP Developer's Handbook.chm HTTP--The Definitive Guide.chm RFC2616 HTTP1.1 PDF,比看网页舒服,呵呵 全是英文的
In Bluetooth Low Energy, one of the standard's developers has written the first comprehensive, accessible introduction to BLE for every system developer, designer, and engineer. Robin Heydon, a ...
HTTP 服务端、客户端开发者必备的开发手册,非常实用,所用的英文也浅显易懂,阅读无难度。
Nios II Software Developer’s Handbook。
Chapter 5: Arrays and Records Chapter 6: All About Strings Part II Chapter 7: Objects Chapter 8: Inheritance Chapter 9: Handling Exceptions Chapter 10: Properties and Events Chapter 11: Interfaces ...
Nios II Software Developer's handbook,来自于官方网站,对于NIOS核的系统开发很有用
Develop professional applications in Java EE 7 with this essential reference guide
Nios II Software Developer’s Handbook.pdf
Chapter 5: Python Data Analysis with pandas Chapter 6: Functions Chapter 7: Classes and Objects Chapter 8: Metaprogramming Chapter 9: Networking and the Internet Chapter 10: Modules and Packages ...
带书签完全版 刚刚找到呵呵 第一部分 Delphi 2009 Handbook 包含源代码 Chapters List This is the list of the book chapters: Part I: Unicode * Chapter 1: What is Unicode? * Chapter 2: The UnicodeString ...
* Chapter 5: Generics * Chapter 6: Anonymous Methods * Chapter 7: More Language and RTL Changes Part III: VCL and Databases * Chapter 8: VCL Improvements * Chapter 9: COM Support in Delphi 2009 * ...
Cocoa Programming Developer's Handbook 英文版 about cocoa apis development skills
by Robin Heydon 如果你是一名工程师,产品设计师,还是营销人员,Robin Heydon的蓝牙低耗能:开发者手册是为你而写的。 蓝牙低耗能与传统蓝牙 蓝牙低功耗技术是专为低功耗,这主要是使用非充电纽扣型电池的低成本...
这是一本敏捷开发的入门书,总结了敏捷开发方法的常用实践。可作为敏捷开发的参考手册。