方法表明了客户端希望服务器对资源执行的动作,常用的方法包括:GET、HEAD、POST、PUT、TRACE、OPTIONS和DELETE,每个服务器可以实现这些方法中的部分或者全部。下面将对这些方法做一个详细的介绍。
GET /seasonal/index-fall.html HTTP/1.1 Host: www.joes-hardware.com Accept: *响应报文如下:
HTTP/1.1 200 OK Content-Type: text/html Context-Length: 617 //body
PUT /product-list.txt HTTP/1.1 Host: www.joes-hardware.com Content-type: text/plain Content-length: 34 //body响应报文:
HTTP/1.1 201 Created Location: http://www.joes-hardware.com/product-list.txt Content-type: text/plain Context-length: 47 http://www.joes-hardware.com/product-list.txt
POST /inventory-check.cgi HTTP/1.1 Host: www.joes-hardware.com Content-type: text/plain Content-length: 18 item-bandsaw 2647服务端交由对应程序处理后,发送响应报文:
HTTP/1.1 200 OK Content-type: text/plain Context-length: 37 The bandsaw model 2647 is in stock!
TRACE /product-list.txt HTTP/1.1 Accept:* Host: www.joes-hardware.com报文经过代理服务器后:
TRACE /product-list.txt HTTP/1.1 Host: www.joes-hardware.com Accept: * Via: 1.1 proxy3.company.com服务器弹回的TRACE响应:
HTTP/1.1 200 OK Content-type: text/plain Content-length: 96 TRACE /product-list.txt HTTP/1.1 Host: www.joes-hardware.com Accept: * Via: 1.1 proxy3.company.comTRACE响应经过代理服务器后:
HTTP/1.1 200 OK Content-type: text/plain Content-length: 96 Via: 1.1 proxy3.company.com TRACE /product-list.txt HTTP/1.1 Host: www.joes-hardware.com Accept: * Via: 1.1 proxy3.company.comTRACE方法主要用于诊断,它主要的缺陷是它假定中间应用程序对各种不同类型请求(GET、HEAD、POST等)的处理都是相同的,如果实际情况不同,那么诊断将不准确。
OPTIONS * HTTP/1.1 Host: www.joes-hardware.com Accept: *响应报文:
HTTP/1.1 200 OK Allow: GET, POST, PUT, OPTIONS Context-length: 0
DELETE /product-list.txt HTTP/1.1 Host: www.joes-hardware.com响应报文:
HTTP/1.1 200 OK Content-type: text/plain Content-length: 54 //响应消息