跨站请求
应该使用 1 号站点向 2 号站点发出请求。让 1 号站点为 localhost,而 2 号站点为 Internet 上的真实服务器。在站点 2 有一个文件 result.php,它接受 GET 请求:
$var = @$_GET['q'] ;
$s = $_GET['s'] ;
$typefile = $_GET['类型'];
如果页面result.php发出请求,那么我们得到的URL是:result.php?q=%F4%FB%E2&type=1&search=%CF%EE%E8%F1%EA%21
如何更好提出请求?有人可以给我举一些例子来帮助我吗?这四天我都在受苦,却没有意识到。
如果有地方写得不清楚请原谅我的英语不好。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设你指的是 Ajax?由于同源政策,您无法通过正常的ajax发出跨站点域请求。因此,托管在本地主机上的脚本只能向本地主机发出请求。
现在,您可以使用 JSONP 或带填充的 JSON 来解决此问题。这允许您从任何来源将脚本文件附加到 dom,以便代码可以在您的站点上执行。就我个人而言,我实际上从未使用过它,并且我知道您必须信任脚本的来源,您不希望在您的网站上运行任意代码。
简而言之,如果您希望本地主机向“site-2”发出请求,您需要在“site-2”上托管一个脚本,该脚本由本地主机加载并发出请求。
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.
读完布拉德刚才所说的内容后,我要做的就是在请求中添加另一个链。
我将调用本地
服务器端
脚本
(跨域proxy)将请求并处理来自其他服务器的数据。参考文献
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