Http methods
来源:互联网 发布:淘宝全网举报有用吗 编辑:程序博客网 时间:2024/05/21 07:09
The set of common methods for HTTP/1.1 is defined below and this set can be expanded based on requirements. These method names are case sensitive and they must be used in uppercase.
Get Method
A GET request retrieves data from a web server by specifying parameters in the URL portion of the request. This is the main method used for document retrieval. The following example makes use of GET method to fetch hello.htm:
GET /hello.htm HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.tutorialspoint.comAccept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alive
The server response against the above GET request will be as follows:
HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Last-Modified: Wed, 22 Jul 2009 19:15:56 GMTETag: "34aa387-d-1568eb00"Vary: Authorization,AcceptAccept-Ranges: bytesContent-Length: 88Content-Type: text/htmlConnection: Closed---------------------------------<html><body><h1>Hello, World!</h1></body></html>
HEAD Method
The HEAD method is functionally similar to GET, except that the server replies with a response line and headers, but no entity-body. The following example makes use of HEAD method to fetch header information about hello.htm:
HEAD /hello.htm HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.tutorialspoint.comAccept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alive
The server response against the above GET request will be as follows:
HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Last-Modified: Wed, 22 Jul 2009 19:15:56 GMTETag: "34aa387-d-1568eb00"Vary: Authorization,AcceptAccept-Ranges: bytesContent-Length: 88Content-Type: text/htmlConnection: Closed
You can notice that here server the does not send any data after header.
POST Method
The POST method is used when you want to send some data to the server, for example, file update, form data, etc. The following example makes use of POST method to send a form data to the server, which will be processed by a process.cgi and finally a response will be returned:
POST /cgi-bin/process.cgi HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.tutorialspoint.comContent-Type: text/xml; charset=utf-8Content-Length: 88Accept-Language: en-usAccept-Encoding: gzip, deflateConnection: Keep-Alive------------------------------<?xml version="1.0" encoding="utf-8"?><string xmlns="http://clearforest.com/">string</string>
The server side script process.cgi processes the passed data and sends the following response:
HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Last-Modified: Wed, 22 Jul 2009 19:15:56 GMTETag: "34aa387-d-1568eb00"Vary: Authorization,AcceptAccept-Ranges: bytesContent-Length: 88Content-Type: text/htmlConnection: Closed---------------------------<html><body><h1>Request Processed Successfully</h1></body></html>
PUT Method
The PUT method is used to request the server to store the included entity-body at a location specified by the given URL. The following example requests the server to save the given entity-boy in hello.htm at the root of the server:
PUT /hello.htm HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.tutorialspoint.comAccept-Language: en-usConnection: Keep-AliveContent-type: text/htmlContent-Length: 182-----------------------------<html><body><h1>Hello, World!</h1></body></html>
The server will store the given entity-body in hello.htm file and will send the following response back to the client:
HTTP/1.1 201 CreatedDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Content-type: text/htmlContent-length: 30Connection: Closed---------------------------<html><body><h1>The file was created.</h1></body></html>
DELETE Method
The DELETE method is used to request the server to delete a file at a location specified by the given URL. The following example requests the server to delete the given file hello.htm at the root of the server:
DELETE /hello.htm HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)Host: www.tutorialspoint.comAccept-Language: en-usConnection: Keep-Alive
The server will delete the mentioned file hello.htm and will send the following response back to the client:
HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Content-type: text/htmlContent-length: 30Connection: Closed---------------------------<html><body><h1>URL deleted.</h1></body></html>
CONNECT Method
The CONNECT method is used by the client to establish a network connection to a web server over HTTP. The following example requests a connection with a web server running on the host tutorialspoint.com:
CONNECT www.tutorialspoint.com HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
The connection is established with the server and the following response is sent back to the client:
HTTP/1.1 200 Connection establishedDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)
OPTIONS Method
The OPTIONS method is used by the client to find out the HTTP methods and other options supported by a web server. The client can specify a URL for the OPTIONS method, or an asterisk (*) to refer to the entire server. The following example requests a list of methods supported by a web server running on tutorialspoint.com:
OPTIONS * HTTP/1.1User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
The server will send an information based on the current configuration of the server, for example:
HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Allow: GET,HEAD,POST,OPTIONS,TRACEContent-Type: httpd/unix-directory
TRACE Method
The TRACE method is used to echo the contents of an HTTP Request back to the requester which can be used for debugging purpose at the time of development. The following example shows the usage of TRACE method:
TRACE / HTTP/1.1Host: www.tutorialspoint.comUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
The server will send the following message in response to the above request:
HTTP/1.1 200 OKDate: Mon, 27 Jul 2009 12:28:53 GMTServer: Apache/2.2.14 (Win32)Connection: closeContent-Type: message/httpContent-Length: 39------------------------------------TRACE / HTTP/1.1Host: www.tutorialspoint.comUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Refrence
http://www.tutorialspoint.com/http/index.htm
- HTTP Methods
- Http methods
- HTTP - Methods
- HTTP methods 与 RESTful API
- Common HTTP Response Codes & HTTP Request Methods
- Ambiguous handler methods mapped for HTTP path
- Ambiguous handler methods mapped for HTTP path
- HTTP TRACE / TRACK Methods Allowed 漏洞修复
- Ambiguous handler methods mapped for HTTP path
- Using HTTP Methods for RESTful Services
- HTTP Methods 和 RESTful Service API 设计
- HTTP Methods 和 RESTful Service API 设计
- METHODS
- Methods
- Methods
- 1.3.2 HTTP REQUEST METHODS(http 请求方式)
- HTTP Request GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE Methods
- HTTP Request GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE Methods
- [DFS && BFS]poj3083
- 在case语句中定义变量的问题
- 反思研一走过的路线
- spark:学习杂记--42
- 如何判别机器是大端还是小端
- Http methods
- uva 1001 奶酪里的老鼠(狄杰斯特拉或弗洛伊德)
- Dijkstra算法求带权图的单源最短路径
- OpenCV中Mat数据结构使用举例
- cocos2dx android版本移植时的Error format not a string literal and no format arguments解决方案
- oracle数据类型和对应的java类型
- poj2965
- RTTI&反射笔记
- Xcode插件