I'm trying to send a HTTP cross-domain request with PUT method with AJAX.
我正在尝试使用带有AJAX的PUT方法发送HTTP跨域请求。
For that, I am using this:
为此,我使用这个:
$.ajax({
url: ipv6Nodo+"/config?param=led",
crossDomain: true,
type: 'PUT',
data: "ls=ON",
success: function(data) {
// Do something with the result
console.log(data);
}
});
I am sniffing on the middle and I am seeing that I am really sending a request with OPTIONS method. That's not the problem, because on the server I can accept PUT or OPTIONS similarly. The problem is that the payload request is empty, there is not ls=ON
, how I want it. If I throw this request to the same domain, I can see the payload. What's the problem?
我在中间嗅,我看到我真的发送了OPTIONS方法的请求。这不是问题,因为在服务器上我可以类似地接受PUT或OPTIONS。问题是有效载荷请求是空的,没有ls = ON,我想要它。如果我将此请求发送到同一个域,我可以看到有效负载。有什么问题?
Thanks in advance
提前致谢
1 个解决方案
#1
0
There's no payload to the OPTIONS
request used with Cross Origin Resource Sharing. It's a "preflight" request to find out whether the server allows CORS from your origin. Once you respond to the OPTIONS
request with the correct CORS headers, you'll get the PUT
request with the data.
与跨源资源共享一起使用的OPTIONS请求没有有效负载。这是一个“预检”请求,以确定服务器是否允许来自您的来源的CORS。一旦您使用正确的CORS标头响应OPTIONS请求,您将获得带有数据的PUT请求。
See the link for details, but basically:
有关详细信息,请参阅链接,但基本上:
- Browser sends
OPTIONS
with CORS request headers. - Server decides whether the request is acceptable from that origin, and if so responds with appropriate CORS response headers.
- Browser responds with the actual
PUT
.
浏览器使用CORS请求标头发送OPTIONS。
服务器决定该请求是否可以从该源接受,如果是,则响应适当的CORS响应头。
浏览器以实际PUT响应。
This is transparent to your client-side ajax
code (but not your server code).
这对您的客户端ajax代码(但不是您的服务器代码)是透明的。
#1
0
There's no payload to the OPTIONS
request used with Cross Origin Resource Sharing. It's a "preflight" request to find out whether the server allows CORS from your origin. Once you respond to the OPTIONS
request with the correct CORS headers, you'll get the PUT
request with the data.
与跨源资源共享一起使用的OPTIONS请求没有有效负载。这是一个“预检”请求,以确定服务器是否允许来自您的来源的CORS。一旦您使用正确的CORS标头响应OPTIONS请求,您将获得带有数据的PUT请求。
See the link for details, but basically:
有关详细信息,请参阅链接,但基本上:
- Browser sends
OPTIONS
with CORS request headers. - Server decides whether the request is acceptable from that origin, and if so responds with appropriate CORS response headers.
- Browser responds with the actual
PUT
.
浏览器使用CORS请求标头发送OPTIONS。
服务器决定该请求是否可以从该源接受,如果是,则响应适当的CORS响应头。
浏览器以实际PUT响应。
This is transparent to your client-side ajax
code (but not your server code).
这对您的客户端ajax代码(但不是您的服务器代码)是透明的。