HTTP defines eight methods (sometimes referred to as "verbs")
你能帮助我找到每个例子,以便我能更好地测试和理解它们吗?
答案 0 :(得分:58)
首先,您应该查看HTTP 1.1 specification,尤其是method definitions部分。
选项获取有关服务器如何与之通信的信息。
请求:
OPTIONS * HTTP/1.1
Host: example.com
响应:
HTTP/1.1 200 OK
Date: …
Allow: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE
Content-Length: 0
获取检索资源。
请求:
GET /foo/bar HTTP/1.1
Host: example.com
响应:
HTTP/1.1 200 OK
Date: …
Content-Type: text/html;charset=utf-8
Content-Length: 12345
<!DOCTYPE …
HEAD 与 GET 类似,但只返回HTTP标头。
请求:
HEAD /foo/bar HTTP/1.1
Host: example.com
响应:
HTTP/1.1 200 OK
Date: …
Content-Type: text/html;charset=utf-8
Content-Length: 12345
POST 创建新资源。
请求:
POST /foo/bar HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
action=addentry&subject=Hello,%20World
响应:
HTTP/1.1 201 Created
Date: …
Content-Length: 0
Location: http://example.com/foo/bar
PUT 将数据发送到服务器。
删除删除现有资源。
TRACE 返回客户端发送的请求标头。
请求:
TRACE /foo/bar HTTP/1.1
Host: example.com
响应:
HTTP/1.1 200 OK
Date: …
Content-Length: 17
Host: example.com
我不确切知道这些例子是否正确。随意纠正它们。
答案 1 :(得分:13)
您可以使用cURL命令行工具试验不同的HTTP方法。例如:
curl --head http://www.google.co.uk
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Sun, 19 Apr 2009 15:33:24 GMT
Expires: -1
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=a2a414b9a84c8ffd:TM=1240155204:LM=1240155204:S=16kZnqzeSxIJT3jv; expires=Tue, 19-Apr-2011 15:33:24 GMT; path=/; domain=.google.co.uk
Server: gws
Transfer-Encoding: chunked