日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Http协议的Delete和Put方法是做什么的?怎么用?

發(fā)布時(shí)間:2023/12/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Http协议的Delete和Put方法是做什么的?怎么用? 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一般來(lái)說(shuō),Web服務(wù)器默認(rèn)的只支持Post和Get這兩種“只讀”的請(qǐng)求方法。但是隨著Ajax XMLHttpRequest 和 REST風(fēng)格應(yīng)用的深入,我們發(fā)現(xiàn)Http 1.1協(xié)議還支持如下請(qǐng)求方法(Request Method):

  • OPTIONS
  • HEAD
  • DELETE
  • PUT
  • TRACE
  • CONNECT
Get是最常用的,就是向Web Server發(fā)請(qǐng)求“獲取”資源;那么Post就是向Web Server“郵寄”一些封裝的數(shù)據(jù)包獲取資源,這兩者方法嚴(yán)格的說(shuō)都是“索取”行為。
顧名思義,Delete方法就是通過(guò)http請(qǐng)求刪除指定的URL上的資源啦,Delete請(qǐng)求一般會(huì)返回3種狀態(tài)碼:
  • 200 (OK) - 刪除成功,同時(shí)返回已經(jīng)刪除的資源
  • 202 (Accepted) - 刪除請(qǐng)求已經(jīng)接受,但沒(méi)有被立即執(zhí)行(資源也許已經(jīng)被轉(zhuǎn)移到了待刪除區(qū)域)
  • 204 (No Content) - 刪除請(qǐng)求已經(jīng)被執(zhí)行,但是沒(méi)有返回資源(也許是請(qǐng)求刪除不存在的資源造成的)

Put方法就不多廢話了,就是往Web Server上直接扔資源(上傳資源)嘛,不過(guò)實(shí)際操作起來(lái)可能會(huì)讓諸位夠暈一壺,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.

上面說(shuō)的都是虛的,實(shí)戰(zhàn)才是硬道理!

  • 首先,我們要讓W(xué)eb Server支持Delete 和 Put請(qǐng)求方法,以大家熟悉的Tomcat為例:

Tomcat的web.xml?文件中配置 org.apache.catalina.servlets.DefaultServlet 的初始化參數(shù)

[xhtml]?view plain?copy
  • <init-param>????
  • ????<param-name>readonly</param-name>????
  • ????<param-value>false</param-value>???
  • </init-param>??
  • readonly參數(shù)默認(rèn)是true,即不允許delete和put操作,所以默認(rèn)的通過(guò)XMLHttpRequest對(duì)象的put或者delete方法訪問(wèn)就會(huì)報(bào)告 http 403 forbidden 錯(cuò)誤。

    • 接下來(lái),從客戶端通過(guò) Ajax XMLHTTPRequest 發(fā)起 DELETE/PUT 請(qǐng)求:

      [javascript]?view plain?copy
    • function?getXMLHTTPRequest(){??
    • ????if?(XMLHttpRequest)????{??
    • ????????return?new?XMLHttpRequest();??
    • ????}?else?{??
    • ????????try{??
    • ????????????return?new?ActiveXObject('Msxml2.XMLHTTP');??
    • ????????}catch(e){??
    • ????????????return?new?ActiveXObject('Microsoft.XMLHTTP');??
    • ????????}??
    • ????}??
    • }??
    • var?req?=?getXMLHTTPRequest();??
    • req.open('DELETE','http://localhost/test.jsp',false);??
    • req.send(null);??
    • document.write(req.responseText);??
    • WebDAV也需要使用到這2種Http請(qǐng)求方法。

    總結(jié)

    以上是生活随笔為你收集整理的Http协议的Delete和Put方法是做什么的?怎么用?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 用我的手指扰乱你 | 337p日本大胆噜噜噜鲁 | 一级黄色片欧美 | 奇米综合 | 亚洲国产av一区二区 | 福利91| 美女被变态侵犯 | 人妻少妇精品一区二区 | av网站网址 | 欧美日韩aaa | 国产免费网 | 四虎免费在线观看 | 精品一性一色一乱农村 | 天天5g天天看| 二色av | 成年视频在线播放 | 黑鬼大战白妞高潮喷白浆 | 天天影视插插插 | 亚洲小说图片区 | 韩国成人在线视频 | caoprom在线| 色性网站 | 色婷婷视频在线 | 色香av | 日韩国产中文字幕 | 手机在线播放av | 毛片毛片毛片毛片毛片毛片毛片 | 国产福利在线观看视频 | 欧美性猛交一区二区三区精品 | 国产精品99久久久 | 久久久久一区二区三区四区 | 欧美日韩日本国产 | 日韩三区在线 | 性少妇videosexfreexxx片 | 欧美xxxx胸大 | 日日操日日 | 最新91视频 | 亚洲欧美色图视频 | 国产精品卡一 | 特黄视频在线观看 | 亚洲区自拍偷拍 | www婷婷av久久久影片 | 国产精品污www一区二区三区 | 国产午夜福利在线播放 | 三区在线观看 | 蜜桃精品噜噜噜成人av | 春色导航 | 99热这里只有精品9 日韩综合在线 | 天天干天天色天天 | 免费欧美一区 | 亚洲国产天堂 | 又粗又猛又爽又黄少妇视频网站 | 黄网页在线观看 | 青青艹在线观看 | 免费看黄色网址 | 亚洲午夜一区二区 | 一级片久久久久 | 国产精品无码999 | 在线天堂中文在线资源网 | 欧美三级中文字幕 | 欧美综合视频在线 | 专业操老外 | 日韩一级生活片 | 操批网站| 亚洲无人区码一码二码三码的含义 | 欧美激情第五页 | 韩日少妇 | 欧美精品成人一区二区三区四区 | 黄色一级片| 欧美色激情 | 久久窝窝 | 欧美激情视频二区 | 啪啪的网站 | 无罩大乳的熟妇正在播放 | 黑白配av| 91大神小宝寻花在线观看 | fc2ppv在线播放 | 久久婷婷网站 | 亚洲www| 奇米影视第四色7777 | 国产成年视频 | 男人天堂欧美 | 五月婷婷六月丁香综合 | 国产一区二区高清 | 99热精品在线 | 无码人妻久久一区二区三区蜜桃 | 波多野结衣视频在线 | 青青草福利视频 | jlzzjlzz国产精品久久 | 一级日韩一级欧美 | 精品视频一区二区三区四区 | 天天插天天搞 | 欧美大奶在线 | 久久丫精品忘忧草西安产品 | av网站入口 | 亚洲成年人网站在线观看 | jizzjizz视频| 性日本xxx| 国产精品久久久精品三级 |