- 安全測試教程
- 安全測試 - 首頁
- 安全測試 - 概述
- 安全測試 - 流程
- 安全測試 - 惡意軟體
- HTTP 協議基礎
- HTTPS 協議基礎
- 編碼和解碼
- 安全測試 - 密碼學
- 安全測試 - 同源策略
- 安全測試 - Cookie
- 駭客攻擊 Web 應用
- 安全測試 - 注入
- 測試身份驗證漏洞
- 測試跨站點指令碼攻擊
- 不安全的直接物件引用
- 測試安全配置錯誤
- 測試敏感資料洩露
- 缺少功能級訪問控制
- 跨站點請求偽造
- 存在漏洞的元件
- 未經驗證的重定向和轉發
- 安全測試 - Ajax 安全
- 測試安全 - Web 服務
- 安全測試 - 緩衝區溢位
- 安全測試 - 拒絕服務
- 測試惡意檔案執行
- 安全測試 - 自動化工具
- 安全測試有用資源
- 安全測試 - 快速指南
- 安全測試 - 有用資源
- 安全測試 - 討論
安全測試 - HTTP 方法
HTTP 方法
HTTP/1.1 定義了一套常用的方法,並且可以根據需要擴充套件這套方法。這些方法名稱區分大小寫,必須使用大寫。
| 序號 | 方法及描述 |
|---|---|
| 1 | GET 用於使用給定的 URI 從給定的伺服器檢索資訊。使用 GET 的請求應該只檢索資料,並且不應該對資料產生任何其他影響。 |
| 2 | HEAD 與 GET 相同,但只傳輸狀態行和報頭部分。 |
| 3 | POST 用於向伺服器傳送資料。例如,使用 HTML 表單傳送客戶資訊、檔案上傳等。 |
| 4 | PUT 用上傳的內容替換目標資源的所有當前表示形式。 |
| 5 | DELETE 刪除 URI 指定的目標資源的所有當前表示形式。 |
| 6 | CONNECT 建立到由給定 URI 標識的伺服器的隧道。 |
| 7 | OPTIONS 描述目標資源的通訊選項。 |
| 8 | TRACE 沿著到目標資源的路徑執行訊息迴路測試。 |
GET 方法
透過在請求的 URL 部分中指定引數來從 Web 伺服器檢索資料。這是用於文件檢索的主要方法。以下示例使用 GET 方法獲取 **hello.htm**:
GET /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.tutorialspoint.com Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive
針對上述 GET 請求發出以下伺服器響應:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
HEAD 方法
在功能上類似於 GET,除了伺服器回覆狀態行和報頭,但不回覆實體主體。以下示例使用 HEAD 方法獲取 **hello.htm** 的報頭資訊:
HEAD /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.tutorialspoint.com Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive
針對上述 GET 請求發出以下伺服器響應:
HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32) Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Vary: Authorization,Accept Accept-Ranges: bytes Content-Length: 88 Content-Type: text/html Connection: Closed
您可以注意到伺服器在報頭之後沒有傳送任何資料。
POST 方法
當您想要向伺服器傳送一些資料時使用。例如,檔案更新、表單資料等。以下簡單示例使用 POST 方法將表單資料傳送到伺服器,該伺服器由 **process.cgi** 處理,最後返回響應:
POST /cgi-bin/process.cgi HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.tutorialspoint.com Content-Type: text/xml; charset = utf-8 Content-Length: 88 Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: Keep-Alive <?xml version = "1.0" encoding = "utf-8"?> <string xmlns = "http://clearforest.com/">string</string>
伺服器端指令碼 **process.cgi** 處理傳遞的資料併發送以下響應:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Request Processed Successfully</h1>
</body>
</html>
PUT 方法
PUT 方法用於請求伺服器將包含的實體主體儲存在給定 URL 指定的位置。以下示例請求伺服器將給定的實體主體儲存在伺服器根目錄下的 **hello.htm** 中:
PUT /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Connection: Keep-Alive
Content-type: text/html
Content-Length: 182
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
伺服器將給定的實體主體儲存在 **hello.htm** 檔案中,並將以下響應傳送回客戶端:
HTTP/1.1 201 Created
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html>
<body>
<h1>The file was created.</h1>
</body>
</html>
DELETE 方法
DELETE 方法用於請求伺服器刪除給定 URL 指定位置的檔案。以下示例請求伺服器刪除伺服器根目錄下的給定檔案 **hello.htm**:
DELETE /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT) Host: www.tutorialspoint.com Accept-Language: en-us Connection: Keep-Alive
伺服器刪除提到的檔案 **hello.htm** 並將以下響應傳送回客戶端:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html>
<body>
<h1>URL deleted.</h1>
</body>
</html>
CONNECT 方法
客戶端使用它透過 HTTP 建立到 Web 伺服器的網路連線。以下示例請求與在主機 tutorialspoint.com 上執行的 Web 伺服器建立連線:
CONNECT www.tutorialspoint.com HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
與伺服器建立連線,並將以下響應傳送回客戶端:
HTTP/1.1 200 Connection established Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32)
OPTIONS 方法
客戶端使用它來找出 Web 伺服器支援哪些 HTTP 方法和其他選項。客戶端可以為 OPTIONS 方法指定 URL,或者使用星號 (*) 來引用整個伺服器。以下示例請求列出在 tutorialspoint.com 上執行的 Web 伺服器支援的方法:
OPTIONS * HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
伺服器根據伺服器的當前配置傳送資訊,例如:
HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32) Allow: GET,HEAD,POST,OPTIONS,TRACE Content-Type: httpd/unix-directory
TRACE 方法
用於將 HTTP 請求的內容回顯給請求者,這可以在開發時用於除錯目的。以下示例顯示了 TRACE 方法的用法:
TRACE / HTTP/1.1 Host: www.tutorialspoint.com User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
伺服器將針對上述請求傳送以下訊息作為響應:
HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache/2.2.14 (Win32) Connection: close Content-Type: message/http Content-Length: 39 TRACE / HTTP/1.1 Host: www.tutorialspoint.com User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)