实现RestFul风格的delete和Put方法的注意点
来源:互联网 发布:简明python教程 mobi 编辑:程序博客网 时间:2024/05/29 09:23
一般来说,Web服务器默认的只支持Post和Get这两种“只读”的请求方法。但是随着Ajax XMLHttpRequest 和 REST风格应用的深入,我们发现Http 1.1协议还支持如下请求方法(Request Method):
OPTIONS
HEAD
DELETE
PUT
TRACE
CONNECT
Get是最常用的,就是向Web Server发请求“获取”资源;那么Post就是向Web Server“邮寄”一些封装的数据包获取资源,这两者方法严格的说都是“索取”行为。
顾名思义,Delete方法就是通过http请求删除指定的URL上的资源啦,Delete请求一般会返回3种状态码:
- 200 (OK) - 删除成功,同时返回已经删除的资源
- 202 (Accepted) - 删除请求已经接受,但没有被立即执行(资源也许已经被转移到了待删除区域)
- 204 (No Content) - 删除请求已经被执行,但是没有返回资源(也许是请求删除不存在的资源造成的)
Put方法就不多废话了,就是往Web Server上直接扔资源(上传资源)嘛,不过实际操作起来可能会让诸位看官喝一壶,E文定义如下:
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.
上面说的都是虚的,实战才是硬道理!
(本文始发于CSDN,作者胡奇的博客:http://blog.csdn.net/kthq )
- 首先,我们要让Web Server支持Delete 和 Put请求方法,以大家熟悉的Tomcat为例:
在Tomcat的web.xml 文件中配置 org.apache.catalina.servlets.DefaultServlet 的初始化参数
readonly参数默认是true,即不允许delete和put操作,所以默认的通过XMLHttpRequest对象的put或者delete方法访问就会报告 http 403 forbidden 错误。
- 接下来,从客户端通过 Ajax XMLHTTPRequest 发起 DELETE/PUT 请求:
- WebDAV也需要使用到这2种Http请求方法。
- 实现RestFul风格的delete和Put方法的注意点
- restful风格中的put请求和delete请求的用法
- Tomcat默认不支持restful风格的put与delete请求
- Ajax中Put和Delete请求传递参数无效的解决方法(Restful风格)
- Ajax中Put和Delete请求传递参数无效的解决方法(Restful风格
- Ajax中Put和Delete请求传递参数无效的解决方法(Restful风格)
- Restful风格中put请求和delete请求
- springMvc实现restful解决put和delete表单提交问题
- springMVC系列(七)——springMVC实现restful风格开发(post、get、put、delete)
- springMVC系列(七)——springMVC实现restful风格开发(post、get、put、delete)
- 配置tomcat支持http delete和put的方法
- 配置tomcat支持http delete和put的方法
- spring mvc 3支持 http 的put和delete方法
- spring mvc 3支持 http 的put和delete方法
- Spring MVC使用RESTful风格的PUT请求
- PHP curl 实现RESTful PUT DELETE 实例
- Spring MVC restful风格之put and delete
- TreeMap的put()和delete()详解
- spark RDD算子(十一)之RDD Action 保存操作saveAsTextFile,saveAsSequenceFile,saveAsObjectFile,saveAsHadoopFile 等
- BIO、NIO、AIO网络编程
- 浅谈ddos防御
- nginx安装及配置虚拟主机
- linux编程之网络编程错误处理
- 实现RestFul风格的delete和Put方法的注意点
- CentOs 安装maven3.0.5
- linux 搭建ss 服务
- Windows 7下使用GNU工具编译C/C++程序的环境搭建
- 新Java中的时间精度
- iOS
- Android studio jni开发出错点
- 技术栈--给自己保存用
- 使用ffmpeg、x264库强制编出关键帧(I帧)