简体   繁体   English

跨域ajax请求失败,并由对等方重置

[英]Cross domain ajax request fails with Reset by peer

I have following configuration. 我有以下配置。 Website on domain1 makes ajax-request (jQuery.ajax) to API on domain2, I can see in error_log api script works fine, but sniffer on client side detects Reset by peer error with no response body. domain1上的网站对domain2上的API进行了ajax请求(jQuery.ajax),我可以在error_log中看到api脚本工作正常,但客户端上的嗅探器检测到没有响应主体的对等错误重置。 This is strange case because there are lot of other similar websites communicating with this api via cross domain request and everything's ok. 这很奇怪,因为还有很多其他类似的网站通过跨域请求与此api通信,并且一切正常。 Can someone give me the clue how to track this? 有人可以给我提示如何跟踪吗? I'm supplying all necessary http-headers on server 我在服务器上提供了所有必要的HTTP标头

<?php      
  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: GET');
  header('Access-Control-Allow-Headers: Origin,cache-control,content-type,man,messagetype,soapaction');

Is there an allowed list on the other side? 另一边是否有允许的清单? I would think so because this: 'Access-Control-Allow-Origin: *' is not recommended. 我认为是这样,因为不建议使用“ Access-Control-Allow-Origin:*”。

Hope this helps. 希望这可以帮助。

FYI, read this: http://enable-cors.org/ cross domain is a two way street apparently. 仅供参考,请阅读以下内容: http : //enable-cors.org/跨域显然是一条双向道路。 It helped me a lot 这对我帮助很大

I think what you need is JSONP, JSONP is allowed to make CORS calls since they have a different origin policy, if you are using jQuery it has built in functions for that. 我认为您需要的是JSONP,允许JSONP进行CORS调用,因为它们具有不同的源策略,如果您使用的是jQuery,则它已为此内置了函数。

See http://api.jquery.com/jquery.getjson/ and http://api.jquery.com/jQuery.ajax/ (the jsonp stuff options) 参见http://api.jquery.com/jquery.getjson/http://api.jquery.com/jQuery.ajax/(jsonp填充选项)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM