安全测试 - HTTP 方法
HTTP 方法
下面定义了 HTTP/1.1 的一组常用方法,可以根据需求扩展此集合。这些方法名称区分大小写,必须使用大写字母。
S.No. | 方法和说明 |
---|---|
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)