问题描述
我正在使用一个API,要求我作为URI的一部分发出HTTP PATCH请求,这是可以通过Javascript做的,我的研究显示我只能执行POST,GET,DELETE和PUT。是否允许PATCH?
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?
谢谢,
推荐答案
我是不确定你的PATCH请求究竟是什么意思,但似乎有可能(至少在Firefox 6和Chromium 12中)。根据,只有 TRACE
和 TRACK
请求的限制。
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.
快速测试用例:
<!-- test.html -->
<script>
var x=new XMLHttpRequest();
x.open("patch", "/");
x.send(null);
</script>
可以使用任何网络服务器,但我选择Python的SimpleHTTPServer模块。
Any webserver can be used, but I choose for Python's SimpleHTTPServer module.
$ 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.
这篇关于你能从Javascript发出HTTP PATCH请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!