Gum*_*mbo 58
首先,您应该了解HTTP 1.1规范,尤其是节方法定义.
选项 获取有关服务器如何与之通信的信息.
请求:
OPTIONS * HTTP/1.1
Host: example.com
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 200 OK
Date: …
Allow: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)GET 检索资源.
请求:
GET /foo/bar HTTP/1.1
Host: example.com
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 200 OK
Date: …
Content-Type: text/html;charset=utf-8
Content-Length: 12345
<!DOCTYPE …
Run Code Online (Sandbox Code Playgroud)HEAD 和GET一样,但只返回HTTP头.
请求:
HEAD /foo/bar HTTP/1.1
Host: example.com
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 200 OK
Date: …
Content-Type: text/html;charset=utf-8
Content-Length: 12345
Run Code Online (Sandbox Code Playgroud)POST 创建新资源.
请求:
POST /foo/bar HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
action=addentry&subject=Hello,%20World
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 201 Created
Date: …
Content-Length: 0
Location: http://example.com/foo/bar
Run Code Online (Sandbox Code Playgroud)PUT 将数据发送到服务器.
删除 删除现有资源.
TRACE 返回客户端发送的请求标头.
请求:
TRACE /foo/bar HTTP/1.1
Host: example.com
Run Code Online (Sandbox Code Playgroud)
响应:
HTTP/1.1 200 OK
Date: …
Content-Length: 17
Host: example.com
Run Code Online (Sandbox Code Playgroud)我不确切知道这些例子是否正确.随意纠正它们.
Joh*_*ley 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24820 次 |
| 最近记录: |