# 前言

官方文档简略翻译。9 不是代表第九篇,而是在 RFC2616 中是第九篇。重要加粗,龟速翻译。

# Method

9.3 GET

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

GET 方法含义是根据请求 URI 检索信息。如果请求 URI 是一个数据处理过程,它产生的数据在响应中应该以一个条目返回,而不是未经处理的文本,除非文本恰好就是处理的输出。

The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.

 

GET 的语义变成“条件性的 GET”,当 header 域的请求消息包括了 If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, 或者 If-Range 之一。一个条件性的 GET 方法,要求条目传输必须包括之前描述的域之一。条件性的 GET 方法意图减少不必要的网络使用,通过缓存条目的技术,多条请求可以不用网页刷新或者再次传送数据,只需要利用已有的数据。

注:意思就是,你比如有 If-Modified-Since 属性,这个属性的值有个时间,一般是网页最后修改的时间。提交 GET 请求的时候,服务器根据这个 If-Modified-Since 判断,如果服务器有该网页修改的版本,则发送给一个新网页;否则就告诉简单的通知用户,用原来的网页,所以不需要再次发送网页。这样就减少了网络流量。

The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section 14.35. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.

GET 的语义变成“部分的 GET”,当 header 域的请求消息包括了 Range。一个部分 GET 请求要求了部分数据被传输,正如区 14.35描述的那样。一个部分 GET 请求意图减少不必要的网络使用,通过传输部分检索条目而不是客户端拥有的全部条目。

注:意思很明白,检索1000条记录和检索10000条记录时间肯定是不一样的。

The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13.

(略)

See section 15.1.3 for security considerations when used for forms.

(略)

9.5 POST

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:

POST 方法用于请求最初的服务器接受了隐藏在请求中的条目,并作为一个新的下级资源,这个资源在 Request-Line(这是什么?) 中可以被 Request-URI 识别。POST 被设计成一个一致的方法,涵盖了以下功能:

      - Annotation of existing resources;
      - Posting a message to a bulletin board, newsgroup, mailing list,
or similar group of articles;
      - Providing a block of data, such as the result of submitting a
form, to a data-handling process; - Extending a database through an append operation.


      - 已经存在的资源的标记

      - 发表一条信息到电子公告牌,新闻组,邮件列表,或者相似文章组

      - 提供一块数据,例如提交一个表格的结果,到一个数据处理的流程

      - 扩展一个数据库,通过一个附加的操作

      注:附加的操作可能指的是数据库的 Insert 操作

The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.

The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.

If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section 14.30).

Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.

POST requests MUST obey the message transmission requirements set out in section 8.2.

See section 15.1.3 for security considerations.

9.6 PUT

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires that the request be applied to a different URI, it MUST send a 301 (Moved Permanently) response; the user agent MAY then make its own decision regarding whether or not to redirect the request.

A single resource MAY be identified by many different URIs. For example, an article might have a URI for identifying "the current version" which is separate from the URI identifying each particular version. In this case, a PUT request on a general URI might result in several other URIs being defined by the origin server.

HTTP/1.1 does not define how a PUT method affects the state of an origin server.

PUT requests MUST obey the message transmission requirements set out in section 8.2.

Unless otherwise specified for a particular entity-header, the entity-headers in the PUT request SHOULD be applied to the resource created or modified by the PUT.

9.7 DELETE

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.

# 译者的话

特定为学习 REST 查看了这篇规范。

从这篇文章可以看出,在 REST 中,经常把 HTTP 方法的 POST GET PUT DELETE 对应成 CRUD 是不完全合适的。GET 、PUT 和 DELETE 对应成 RUD 倒是无可厚非;POST 对应成 Create 似乎不太合适,因为POST 方法原意并不是创建什么东西,POST 方法用途很广。

# Reference

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

HTTP协议学习 - 9 Method Definitions的更多相关文章

  1. http协议学习系列

    深入理解HTTP协议(转)  http://www.blogjava.net/zjusuyong/articles/304788.html http协议学习系列   1. 基础概念篇 1.1 介绍 H ...

  2. http协议学习系列(一个博文链接)

    深入理解HTTP协议(转) http协议学习系列(转自:http://www.blogjava.net/zjusuyong/articles/304788.html) 1. 基础概念篇 1.1 介绍 ...

  3. 转 #HTTP协议学习# (一)request 和response 解析

    http://www.cnblogs.com/bukudekong/p/3834020.html #HTTP协议学习# (一)request 和response 解析   注:本文转自:http:// ...

  4. TCP/IP协议学习(五) 基于C# Socket的C/S模型

    TCP/IP协议作为现代网络通讯的基石,内容包罗万象,直接去理解理论是比较困难的:然而通过实践先理解网络通讯的理解,在反过来理解学习TCP/IP协议栈就相对简单很多.C#通过提供的Socket API ...

  5. BGP协议学习总结

    BGP学习总结 BGP是目前使用的唯一的自治系统间的路由协议,它是一种矢量路由协议,基于TCP的179号端口,它采用单播增量更新的方式更新路由,与其他的路由协议不同的是,BGP只要TCP可达,就可以建 ...

  6. 设计模式学习--Factory Method

    What Factory Method:定义一个创建对象的接口,让子类来决定实例化哪一个类.Factory Method使一个类的实例化延迟到其子类. Why Factory Method是一个比較基 ...

  7. TCP/IP协议学习之实例ping命令学习笔记

    TCP/IP协议学习之实例ping命令学习笔记(一) 一. 目的为了让网络协议学习更有效果,在真实网络上进行ping命令前相关知识的学习,暂时不管DNS,在内网中,进行2台主机间的ping命令的整个详 ...

  8. HTTP协议学习笔记(四)

    HTTP协议学习笔记(四) 与 HTTP 协作的 Web 服务器 一台 Web 服务器可搭建多个独立域名的 Web 网站,也可作为通信路径上的中转服务器提升传输效率. 1.用单台虚拟主机实现多个域名 ...

  9. HTTP协议学习笔记(三)

    HTTP协议学习笔记(三) 1.状态码告知从服务器端返回的请求结果 状态码的职责是当客户端向服务端向服务端发送请求时,描述返回的请求结果.借助状态码,用户可以知道服务端是正常处理了请求,还是出现了错误 ...

随机推荐

  1. 使Sublime Text支持除UTF8外多种编码 - ConvertToUTF8

    前几天,在使用了Sublime Text多天之后,感觉完全可以代替系统自带记事本,所以就通过其打开了一个记事本文件,但是打开之后尽然是乱码,在思考了一下之后想到记事本的编码是ANSI编码,那么这就应该 ...

  2. Android bitmap绘制文字自动换行

    public Bitmap getNewBitMap(String text) { Bitmap newBitmap = Bitmap.createBitmap(,, Config.ARGB_4444 ...

  3. 切换-5.7-GTID复制切换成传统复制

    mysql5.7 gtid和传统复制在线切换,5.7.6 之后 不用重启可以直接在线切换   基本环境   Master Slave MySQL版本 MySQL-5.7.16-X86_64 MySQL ...

  4. 【u213&&t037】修剪花卉

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] ZZ对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题. 一天他早晨骑车去上 ...

  5. php超实用正则表达式有哪些

    php超实用正则表达式有哪些 一.总结 一句话总结: 二.php几个超实用正则表达式 对于开发人员来说,正则表达式是一个非常有用的功能,它提供了 查找,匹配,替换 句子,单词,或者其他格式的字符串.这 ...

  6. Erlang中的record与宏

    http://www.cnblogs.com/me-sa/archive/2011/07/20/erlang0006.html 在Erlang中使用Tuple ,数据项的顺序\数量都是确定的,一旦数据 ...

  7. 【codeforces 782B】The Meeting Place Cannot Be Changed

    [题目链接]:http://codeforces.com/contest/782/problem/B [题意] 每个人都有一个速度,只能往上走或往下走; 然后让你找一个地方,所有人都能够在t时间内到达 ...

  8. Cocos2d-x 脚本语言Lua基本语法

    Cocos2d-x 脚本语言Lua基本语法 前面一篇博客对Lua这门小巧的语言进行了简单的介绍.本篇博客来给大家略微讲一下Lua的语法.不会长篇累牍得把Lua的全部语法都讲一遍,这里通过下面几点来讲L ...

  9. Lua转让C功能

    在上一篇文章中(C调用lua函数)中.讲述了怎样用c语言调用lua函数,通常,A语言能调用B语言,反过来也是成立的.正如Java 与c语言之间使用JNI来互调.Lua与C也能够互调. 当lua调用c函 ...

  10. js判断两个时间段是否有交集

    //判断两个时间是否有交集 function isDateIntersection(start1, end1, start2, end2) { var startdate1 = new Date(st ...