Author: Xu FC
Method = token,大小寫敏感。
標準 Methods
| Method | Description |
|---|---|
| GET | 獲取目標資源 |
| HEAD | 應答中的頭部與 GET,但應答中不帶 body |
| POST | 指定資源處理請求中的 payload |
| PUT | 請求中的 payload 替換指定資源 |
| DELETE | 刪除指定資源 |
| OPTIONS | 獲取目標資源所支持的 method |
| CONNECT | Establish a tunnel to the server identified by the target resource. |
| TRACE | 使源服務器在應答 body 中原樣返回請求 |
RFC: https://tools.ietf.org/html/rfc7231
Methods 分類
- Safe Methods
對資源的訪問權限是 read-only 的請求 method,被歸類為 safe methods,例如 GET, HEAD, OPTIONS, TRACE。 - Idempotent Methods
多次請求與一次請求所得到的結果相同,被歸類為 idempotent method,例如 PUT, DELETE 和 safe methods。 - Cacheable Methods
應答允許緩存的methods,例如 GET, HEAD, POST (大多數(shù)實現(xiàn)只支持GET 和 HEAD)。 - 擴展 methods: HTTP 支持 method 擴展,詳細請見https://tools.ietf.org/html/rfc7231#section-8.1
GET
- 標準的 GET 請求將獲取源服務器上指定資源的副本,即應答中的body,但 GET 請求并不僅限于此,很多實現(xiàn)中, GET 請求也用于傳輸數(shù)據(jù)查詢數(shù)據(jù)庫記錄等。GET 請求中不帶有 body, 但 RFC 中并沒有強制 GET 請求不能帶有 body。
GET / HTTP/1.1
Host: 172.16.77.99
HTTP/1.1 200 OK
Date: Fri, 23 Mar 2018 11:50:14 GMT
Server: Apache/2.2.14 (Win32)
Set-cookie: t=1521805814119777
test: t=1521805814119777
Content-Length: 587
Content-Type: text/html;charset=UTF-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>...</html>
HEAD
- 應答中的頭部與 GET 相同,但應答中不帶 body,常用于確認資源的有效性、可訪問性、最近是否有修改。
- HEAD 請求中不帶有 body, 但 RFC 中并未強制要求不帶body。
HEAD / HTTP/1.1
Host: aaa
HTTP/1.1 200 OK
Date: Fri, 23 Mar 2018 11:52:39 GMT
Server: Apache/2.2.14 (Win32)
Set-cookie: t=1521805959699233
test: t=1521805959699233
Content-Type: text/html;charset=UTF-8
HEAD / HTTP/1.1
Host: aaa
Range: bytes=-10
HTTP/1.1 206 Partial Content
Date: Tue, 29 May 2018 18:28:03 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Sat, 20 Nov 2004 07:16:26 GMT
ETag: "100000000f6f7-2c-3e94b66c2e680"
Accept-Ranges: bytes
Content-Length: 10
Content-Range: bytes 34-43/44
Content-Type: text/html
POST
待補充
PUT
待補充
DETETE
待補充
OPTIONS
- 獲取目標資源所支持的 methods,如果 URI 為 * ,則返回的 methods 為服務器支持的 methods,如果不是 * , 則返回的 methods 為該資源支持的 methods。
OPTIONS 請求不帶 body。 - Allow:應答中的header,列出指定資源所支持的method
OPTIONS /WebGoat/login.mvc HTTP/1.1
Host: 179.1.1.63:8061
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Content-Length: 0
Date: Fri, 23 Mar 2018 18:39:50 GMT
CONNECT
待補充
TRACE
- 使源服務器在應答 body 中原樣返回請求,一般用于調試。
TRACE / HTTP/1.1
Host: 172.16.77.99
HTTP/1.1 200 OK
Date: Fri, 23 Mar 2018 11:58:11 GMT
Server: Apache/2.2.14 (Win32)
Transfer-Encoding: chunked
Content-Type: message/http
28
TRACE / HTTP/1.1
Host: 172.16.77.99
0