简体   繁体   中英

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. This is strange case because there are lot of other similar websites communicating with this api via cross domain request and everything's ok. Can someone give me the clue how to track this? I'm supplying all necessary http-headers on server

<?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.

Hope this helps.

FYI, read this: http://enable-cors.org/ cross domain is a two way street apparently. 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.

See http://api.jquery.com/jquery.getjson/ and http://api.jquery.com/jQuery.ajax/ (the jsonp stuff options)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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