使用客户端的 IP 获取内容
我在这里有点尴尬,因为我试图通过使用客户端的浏览器而不是服务器来远程获取内容。但我的规格让我觉得这是不可能的,我确实花了一整天的时间,但没有成功。
- 我需要获取的数据位于远程服务器上。
- 我不拥有该服务器(我无法对其进行任何修改)。
- 它是一个字符串,我需要获取它并将其传递给 PHP。
- 它必须是客户端(浏览网站的用户)浏览器实际获取数据(它需要是它的IP,而不是服务器)。
而且,通过跨域策略,我似乎无法绕过它。我已经知道了,仍然尝试了一个简单的 Ajax 查询,但失败了。然后我想“为什么不使用 iFrames”,但同样的限制似乎也适用于它们。然后我读到了有关使用 YQL (http://developer.yahoo.com/yql/) 的信息,但我注意到我试图访问的服务器阻止了 YQL 的用户代理,使得无法使用此技术。
所以,这就是我能想到或找到的一切。但我不敢相信不可能实现这样的事情,这看起来并不难......
哦,我的 Javascript 知识非常基础,这也没有帮助。
I'm a bit embarrassed here because I am trying to get content remotely, by using the client's browser and not the server. But I have specifications which make it look impossible to me, I literally spent all day on it with no success.
- The data I need to fetch is on a distant server.
- I don't own this server (I can't do any modification to it).
- It's a string, and I need to get it and pass it to PHP.
- It must be the client's (user browsing the website) browser that actually gets the data (it needs to be it's IP, and not the servers).
And, with the cross-domain policy I don't seem to be able to get around it. I already knew about it, still tried a simple Ajax query, which failed. Then I though 'why not use iFrames', but the same limitation seems to apply to them too. I then read about using YQL (http://developer.yahoo.com/yql/) but I noticed the server I was trying to reach blocked YQL's user-agent making it impossible to use this technique.
So, that's all I could think about or find. But I can't believe it's not possible to achieve such a thing, that doesn't even look hard...
Oh, and my Javascript knowledge is very basic, this mustn't help either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是同源策略存在的原因之一。您试图让您的网页在用户不知情的情况下访问不同服务器上的数据,并且没有获得其他服务器的“许可”。
如果不建立双向信任系统(即修改“其他”服务器),我相信这是不可能的。
即使有了新的 xhr 和跨域支持,仍然需要双向信任才能进行通信。
您可以考虑采用胖客户端方法,或者尝试@selbie 建议并需要手动用户交互。
This is one reason that the same-origin policy exists. You're trying to have your webpage access data on a different server, without the user knowing, and without having "permission" from the other server to do so.
Without establishing a two-way trust system (ie modifying the 'other' server), I believe this is not possible.
Even with new xhr and crossdomain support, two-way trust is still required for the communication to work.
You could consider a fat-client approach, or try @selbie suggestion and require manual user interaction.
-- 来自 http://www.mozilla.org/projects/security/ Components/same-origin.html
现在,如果您想进行一些黑客攻击来获得它... 访问此网站
注意:我从未尝试过以下任何方法上述网站并不能保证其成功
-- From http://www.mozilla.org/projects/security/components/same-origin.html
Now if you wish to do some hackery to get it... visit this site
Note: I have never tried any of the methods on the aforementioned site and cannot guarantee their success
我只能看到一个非常丑陋的解决方案:iFrames。 本文包含一些不错的入门信息。
I can only see a really ugly solution: iFrames. This article contains some good informations to start with.
您可以使用 Flash 应用程序来做到这一点:
带有 crossdomain.xml 文件的 flash (但不会有帮助,因为你不t 控制其他服务器)
在新浏览器上有 CORS - 需要在服务器端设置 Access-Control-Allow-Origin 标头。
您还可以尝试使用 JSONP (但我认为这不会'无法工作,因为您不拥有其他服务器)。
我认为您需要硬着头皮找到其他方式来获取内容(例如在服务器端)。
You could do it with flash application:
flash with a crossdomain.xml file (won't help though since you don't control the other server)
On new browsers there is CORS - requires Access-Control-Allow-Origin header set on the server side.
You can also try to use JSONP (but I think that won't work since you don't own the other server).
I think you need to bite the bullet and find some other way to get the content (on the server side for example).