# 前言

官方文档简略翻译。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. html5-4 HTML5超链接、URL地址和表格

    html5-4 HTML5超链接.URL地址和表格 一.总结 一句话总结: 1.cellspace有什么用? 清除表格的单元格间距 26 <table border='1px' cellspac ...

  2. 微信小程序从零开始开发步骤(三)

    上一章节,我们分享了如何创建一个新的页面和设置页面的标题,这一章我们来聊聊底部导航栏是如何实现的.即点击底部的导航,会实现不同对应页面之间的切换. 我们先来看个我们要实现的底部导航栏的效果图:(三个导 ...

  3. 【u120】红牌

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 某地临时居民想获得长期居住权就必须申请拿到红牌.获得红牌的过程是相当复杂 ,一共包括N个步骤.每一步骤 ...

  4. poj1066--Treasure Hunt(规范相交)

    题目链接:点击打开链接 题目大意:一个正方形的墓葬内有n堵墙,每堵墙的两个顶点都在正方形的边界上,如今这些墙将墓葬切割成了非常多小空间,已知正方形内的一个点上存在宝藏,如今我们要在正方形的外面去得到宝 ...

  5. idea中建立一个OSGI项目

    参考网址:http://chenjingbo.iteye.com/blog/1893597 首先我使用的是equinox作为我的osgi framework 直接在官网上解压下载即可,第一步creta ...

  6. 要求两个异步任务都完成后, 才能回到主线程:dispatch_group_t

    需求:两个异步任务都完成后, 回到主线程 /** 1.下载图片1和图片2 2.将图片1和图片2合并成一张图片后显示到imageView上 思考: * 下载图片 : 子线程 * 等2张图片都下载完毕后, ...

  7. ASCII码(转)

    ASCII(American Standard Code for Information Interchange,美国标准信息交换代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英语和其他西欧 ...

  8. Ultra-wideband (UWB) secure wireless device pairing and associated systems

    Methods and systems are disclosed for ultra-wideband (UWB) secure wireless device pairing. Secure pa ...

  9. Spring boot quartz的相关资源

    https://github.com/82253452/banner https://github.com/lvhao/schedule-job/tree/master/src/main/java/c ...

  10. Cython 的学习

    开发效率极高的 Python 一直因执行效率过低为人所诟病,Cython 由此诞生,特性介于 Python 和 C 语言之间. Cython 学习 1. Cython 是什么? 它是一个用来快速生成 ...