您可以从 Javascript 发出 HTTP PATCH 请求吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7502278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can you make a HTTP PATCH request from Javascript?
提问by NSA
I am working with an API that requires me to make an HTTP PATCH request as part of the URI, is this possible to do from Javascript, my research is showing that I can only do POST, GET, DELETE, and PUT. Is PATCH allowed?
我正在使用一个 API,它要求我将 HTTP PATCH 请求作为 URI 的一部分,这是否可以从 Javascript 中完成,我的研究表明我只能执行 POST、GET、DELETE 和 PUT。是否允许 PATCH?
Thank you,
谢谢,
采纳答案by Lekensteyn
I'm not sure what you exactly mean by a "PATCH" request, but it seems to be possible (at least in Firefox 6 and Chromium 12). According to the Mozilla source code, there is only a limitation of TRACE
and TRACK
requests.
我不确定“PATCH”请求的确切含义,但它似乎是可能的(至少在 Firefox 6 和 Chromium 12 中)。根据Mozilla 源代码,只有TRACE
和TRACK
requests的限制。
A quick testcase:
一个快速的测试用例:
<!-- test.html -->
<script>
var x=new XMLHttpRequest();
x.open("patch", "/");
x.send(null);
</script>
Any webserver can be used, but I choose for Python's SimpleHTTPServer module.
可以使用任何网络服务器,但我选择 Python 的 SimpleHTTPServer 模块。
$ ls
test.html
$ python -m SimpleHTTPServer
localhost - - [21/Sep/2011 17:32:11] "GET /test.html HTTP/1.1" 200 -
localhost - - [21/Sep/2011 17:32:11] code 501, message Unsupported method ('patch')
localhost - - [21/Sep/2011 17:32:11] "patch / HTTP/1.1" 501 -
So, as long as the server supports the method, the request get's passed.
因此,只要服务器支持该方法,请求 get 就会通过。
回答by sod
As of some research the PATCH
method seems to be new (march 2010 http://tools.ietf.org/html/rfc5789) so if you try to define PATCH
on an XMLHttpRequest it may work, but only on very latest revisions of modern browsers. Don't have a supported browser list found, yet.
根据一些研究,该PATCH
方法似乎是新的(2010 年 3 月http://tools.ietf.org/html/rfc5789),因此如果您尝试PATCH
在 XMLHttpRequest上定义它可能会起作用,但仅适用于现代浏览器的最新版本。还没有找到受支持的浏览器列表。