下圖是我用IE的開發人員工具截取的一個Http Request請求的Header.
下圖是我用IE的開發人員工具截取的一個Http Response的Header.
header常用指令
header分為三部分:第一部分為HTTP協議的版本(HTTP-Version);
第二部分為狀態代碼(Status);
第三部分為原因短語(Reason-Phrase)。
//發送一個200 正常響應
header('HTTP/1.1 200 OK');
// set 404 header: 頁面沒找到
header('HTTP/1.1 404 Not Found');
//頁面被永久刪除,可以告訴搜索引擎更新它們的urls
// set Moved Permanently header (good for redrictions)
// use with location header
header('HTTP/1.1 301 Moved Permanently');
// 訪問受限
header('HTTP/1.1 403 Forbidden');
// 服務器錯誤
header('HTTP/1.1 500 Internal Server Error');
// 重定向到一個新的位置
// redirect to a new location:
header('Location: http://www.example.org/');
延遲一段時間后重定向
// redrict with delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
// 覆蓋 X-Powered-By value
// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
// 內容語言 (en = English)
// content language (en = English)
header('Content-language: en');
//最后修改時間(在緩存的時候可以用到)
// last modified (good for caching)
$time = time() - 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// 告訴瀏覽器要獲取的內容還沒有更新
// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');
// 設置內容的長度 (緩存的時候可以用到):
// set content length (good for caching):
header('Content-Length: 1234');
// 用來下載文件:
// Headers for an download:
header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// 禁止緩存當前文檔:
// load the file to send:readfile('example.zip');
// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// 設置內容類型:
// Date in the pastheader('Pragma: no-cache');
// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain'); // plain text file
header('Content-Type: image/jpeg'); // JPG picture
header('Content-Type: application/zip'); // ZIP file
header('Content-Type: application/pdf'); // PDF file
header('Content-Type: audio/mpeg'); // Audio MPEG (MP3,...) file
header('Content-Type: application/x-shockwave-flash'); // Flash animation
// 顯示登錄對話框,可以用來進行HTTP認證
// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';?>
// 發送一個200 正常響應
header("HTTP/1.1 200 OK");
// 發送一個404 找不到資源響應
header('HTTP/1.1 404 Not Found');
// 發送一個301 永久重定向
header('HTTP/1.1 301 Moved Permanently');
// 發送一個503 網站暫時不能訪問
header('HTTP/1.1 503 Service Temporarily Unavailable');
// 網頁重定向
header('Location: http://www.php-chongqing.com/');
// 設置網頁3秒后重定向
header('Refresh: 3; url=http://www.php-chongqing.com/');
echo '網頁將在3秒后跳轉到http://www.php-chongqing.com';
// 設置網頁編碼
header('Content-Type: text/html; charset=utf-8');
// 設置網頁輸出一個圖片流
header('Content-Type: image/jpeg');
// 設置網頁輸出一個pdf文檔
header('Content-Type: application/pdf');
// 設置網頁輸出一個zip文檔
header('Content-Type: application/zip');
Responses 部分
Header |
解釋 |
示例 |
Accept-Ranges |
表明服務器是否支持指定范圍請求及哪種類型的分段請求 |
Accept-Ranges: bytes |
Age |
從原始服務器到代理緩存形成的估算時間(以秒計,非負) |
Age: 12 |
Allow |
對某網絡資源的有效的請求行為,不允許則返回405 |
Allow: GET, HEAD |
Cache-Control |
告訴所有的緩存機制是否可以緩存及哪種類型 |
Cache-Control: no-cache |
Content-Encoding |
web服務器支持的返回內容壓縮編碼類型。 |
Content-Encoding: gzip |
Content-Language |
響應體的語言 |
Content-Language: en,zh |
Content-Length |
響應體的長度 |
Content-Length: 348 |
Content-Location |
請求資源可替代的備用的另一地址 |
Content-Location: /index.htm |
Content-MD5 |
返回資源的MD5校驗值 |
Content-MD5: Q2hlY2sgSW50ZWdyaXR5IQ== |
Content-Range |
在整個返回體中本部分的字節位置 |
Content-Range: bytes 21010-47021/47022 |
Content-Type |
返回內容的MIME類型 |
Content-Type: text/html; charset=utf-8 |
Date |
原始服務器消息發出的時間 |
Date: Tue, 15 Nov 2010 08:12:31 GMT |
ETag |
請求變量的實體標簽的當前值 |
ETag: “737060cd8c284d8af7ad3082f209582d” |
Expires |
響應過期的日期和時間 |
Expires: Thu, 01 Dec 2010 16:00:00 GMT |
Last-Modified |
請求資源的最后修改時間 |
Last-Modified: Tue, 15 Nov 2010 12:45:26 GMT |
Location |
用來重定向接收方到非請求URL的位置來完成請求或標識新的資源 |
Location: http://www.zcmhi.com/archives/94.html |
Pragma |
包括實現特定的指令,它可應用到響應鏈上的任何接收方 |
Pragma: no-cache |
Proxy-Authenticate |
它指出認證方案和可應用到代理的該URL上的參數 |
Proxy-Authenticate: Basic |
refresh |
應用於重定向或一個新的資源被創造,在5秒之后重定向(由網景提出,被大部分瀏覽器支持) |
Refresh: 5; url= http://www.zcmhi.com/archives/94.html |
Retry-After |
如果實體暫時不可取,通知客戶端在指定時間之后再次嘗試 |
Retry-After: 120 |
Server |
web服務器軟件名稱 |
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) |
Set-Cookie |
設置Http Cookie |
Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1 |
Trailer |
指出頭域在分塊傳輸編碼的尾部存在 |
Trailer: Max-Forwards |
Transfer-Encoding |
文件傳輸編碼 |
Transfer-Encoding:chunked |
Vary |
告訴下游代理是使用緩存響應還是從原始服務器請求 |
Vary: * |
Via |
告知代理客戶端響應是通過哪里發送的 |
Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1) |
Warning |
警告實體可能存在的問題 |
Warning: 199 Miscellaneous warning |
WWW-Authenticate |
表明客戶端請求實體應該使用的授權方案 |
WWW-Authenticate: Basic |
更多參見 w3c官網Header Field Definitions
Content-Type |
請求的與實體對應的MIME信息 |
Content-Type: application/x-www-form-urlencoded |
Date |
請求發送的日期和時間 |
Date: Tue, 15 Nov 2010 08:12:31 GMT |
Expect |
請求的特定的服務器行為 |
Expect: 100-continue |
From |
發出請求的用戶的Email |
From: user@email.com |
Host |
指定請求的服務器的域名和端口號 |
Host: www.zcmhi.com |
If-Match |
只有請求內容與實體相匹配才有效 |
If-Match: “737060cd8c284d8af7ad3082f209582d” |
If-Modified-Since |
如果請求的部分在指定時間之后被修改則請求成功,未被修改則返回304代碼 |
If-Modified-Since: Sat, 29 Oct 2010 19:43:31 GMT |
If-None-Match |
如果內容未改變返回304代碼,參數為服務器先前發送的Etag,與服務器回應的Etag比較判斷是否改變 |
If-None-Match: “737060cd8c284d8af7ad3082f209582d” |
If-Range |
如果實體未改變,服務器發送客戶端丟失的部分,否則發送整個實體。參數也為Etag |
If-Range: “737060cd8c284d8af7ad3082f209582d” |
If-Unmodified-Since |
只在實體在指定時間之后未被修改才請求成功 |
If-Unmodified-Since: Sat, 29 Oct 2010 19:43:31 GMT |
Max-Forwards |
限制信息通過代理和網關傳送的時間 |
Max-Forwards: 10 |
Pragma |
用來包含實現特定的指令 |
Pragma: no-cache |
Proxy-Authorization |
連接到代理的授權證書 |
Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== |
Range |
只請求實體的一部分,指定范圍 |
Range: bytes=500-999 |
Referer |
先前網頁的地址,當前請求網頁緊隨其后,即來路 |
Referer: http://www.zcmhi.com/archives/71.html |
TE |
客戶端願意接受的傳輸編碼,並通知服務器接受接受尾加頭信息 |
TE: trailers,deflate;q=0.5 |
Upgrade |
向服務器指定某種傳輸協議以便服務器進行轉換(如果支持) |
Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11 |
User-Agent |
User-Agent的內容包含發出請求的用戶信息 |
User-Agent: Mozilla/5.0 (Linux; X11) |
Via |
通知中間網關或代理服務器地址,通信協議 |
Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1) |
Warning |
關於消息實體的警告信息 |
Warn: 199 Miscellaneous warning
|
Requests部分
Header |
解釋 |
示例 |
Accept |
指定客戶端能夠接收的內容類型 |
Accept: text/plain, text/html |
Accept-Charset |
瀏覽器可以接受的字符編碼集。 |
Accept-Charset: iso-8859-5 |
Accept-Encoding |
指定瀏覽器可以支持的web服務器返回內容壓縮編碼類型。 |
Accept-Encoding: compress, gzip |
Accept-Language |
瀏覽器可接受的語言 |
Accept-Language: en,zh |
Accept-Ranges |
可以請求網頁實體的一個或者多個子范圍字段 |
Accept-Ranges: bytes |
Authorization |
HTTP授權的授權證書 |
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== |
Cache-Control |
指定請求和響應遵循的緩存機制 |
Cache-Control: no-cache |
Connection |
表示是否需要持久連接。(HTTP 1.1默認進行持久連接) |
Connection: close |
Cookie |
HTTP請求發送時,會把保存在該請求域名下的所有cookie值一起發送給web服務器。 |
Cookie: $Version=1; Skin=new; |
Content-Length |
請求的內容長度 |
Content-Length: 348 |
轉載地址:http://www.cnblogs.com/breezemist/p/3483777.html