HTTP Header

 

一、http request與http response裡面,都有包著Http header

用作流程如下圖

 

二、一個request範例為

GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1
Host: net.tutsplus.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120
Pragma: no-cache
Cache-Control: no-cache

範例第一行的GET /.....,就是request line

一個最小的http request可能會是

GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1
Host: net.tutsplus.com

 

三、一個response範例

HTTP/1.x 200 OK
Transfer-Encoding: chunked
Date: Sat, 28 Nov 2009 04:36:25 GMT
Server: LiteSpeed
Connection: close
X-Powered-By: W3 Total Cache/0.8
Pragma: public
Expires: Sat, 28 Nov 2009 05:36:25 GMT
Etag: "pub1259380237;gz"
Cache-Control: max-age=3600, public
Content-Type: text/html; charset=UTF-8
Last-Modified: Sat, 28 Nov 2009 03:50:37 GMT
X-Pingback: http://net.tutsplus.com/xmlrpc.php
Content-Encoding: gzip
Vary: Accept-Encoding, Cookie, User-Agent
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Top 20+ MySQL Best Practices - Nettuts+</title>
<!-- ... rest of the html ... -->

範例的第一行就是status line

 

四、Media Type(ContentType)

Media Type資訊有兩種組成方式

1、top-level type name / subtype name [;parameters]

2、top-level type name / [ tree. ] subtype name [ +suffix ] [;parameters]

top-level type name有九種:application、audio、example、image、message、model、multipart、text、video,

而subtype name則有多種表示方式,單純的subtype name的如"text/html",有加參數的如"text/plain;charset=utf-8",

複雜的如"application/vnd.oasis.opendocument.text"。

詳細請參考Internet Assigned Numbers Authority-Media Types

 

參考資料:

HTTP Headers for Dummies

HTTP 標頭參照

List of HTTP header fields

Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

 

http status

HTTP Status Codes

HTTP狀態碼