cross-site request

半世苍凉 提交于 2019-12-11 07:27:43

问题


Should be done with the site number 1 request to the site number 2. Let the number one site will be localhost, and the site number 2 - the real server on the Internet. At site 2 there is a file result.php, which takes GET-requests:

$var = @$_GET['q'] ;
$s = $_GET['s'] ;
$typefile = $_GET['type'];


If the page result.php make a request, then we obtain the URL: result.php?q=%F4%FB%E2&type=1&search=%CF%EE%E8%F1%EA%21

How better to make a request? Can someone show me some examples to help? For 4 days I suffer, does not realize.

If somewhere is not clear written excuse my bad English with.


回答1:


I'm assuming you mean with Ajax? You can't make cross-site domain requests through normal ajax due to the same origin policy. As such, a script hosted on localhost, can only make requests to localhost.

Now, you can get around this with JSONP, or JSON with padding. This allows you to append a script file to the dom from any source so the code can execute on your site. Personally, I've actually never used it and I understand you have to trust the origin of the script, you don't want arbitrary code being run on your site.

So in a nutshell, if you want localhost to make a request to 'site-2' you need to host a script on 'site-2' that gets loaded by your localhost and makes the request.




回答2:


After reading what brad just said, what i would do is to add another chain to the request.

I'll be calling a local serverside script (cross domain proxy) that will request and process the data from the other server.

References

  • Cross-Domain Proxy
  • Same Origin Policy


来源:https://stackoverflow.com/questions/3711035/cross-site-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!