跨域javascript来访问本地主机。可能? [英] Cross domain javascript to access localhost. Possible?

查看:89
本文介绍了跨域javascript来访问本地主机。可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我需要javascript来访问本地主机上的网络服务器。这个localhost网络服务器是我们的控制,所以我们可以有任何软件运行在它。



您会如何做?我已经看到了类似YQL的东西,但这访问另一个域从互联网 。这种访问会导致很多防火墙等问题。所以我想访问与运行浏览器的同一台计算机。



如何使用javascript和任何在localhost服务器上运行的软件?



此外,javascript是从互联网网站运行。并且本地主机服务器不会在互联网网站所在的同一端口上运行。



这可以吗?我知道跨域限制,但我也看到有方法围绕他们,如YQL。像YQL这样的东西如何工作?

解决方案

您可以尝试使用 JSONP



在JSONP中,您可以使用动态创建的脚本标记来访问其他域。 URL可用于将数据传递到服务器,并且返回的脚本可以调用回调以返回数据。就我记得,对向localhost发出请求没有特殊限制(与文件系统不同),但我可能是错误的。


for one reason or another I need for javascript to access a webserver on the localhost. This localhost webserver is under our control so we can have whatever software running in it.

How would you do this? I've seen things like YQL but this accesses another domain from the internet. This kind of access causes a lot of problems with firewalls and such. So I want to access the same computer that the browser is running on.

How would you do this with javascript and whatever software running on the localhost server?

Also, the javascript is being run from an internet site. And the localhost server will not be running on the same port are the internet website is.

Is this possible to do? I know about the cross-domain restrictions but I've also seen there are ways around them such as YQL. How does something like YQL work? How would you reimplement it?

解决方案

You could try something like JSONP.

In JSONP, you use dynamically created script tags to access things in other domains. The URL can be used to pass data to the server, and the returned script can call a callback to return data. As far as I remember, there are no special restrictions on making requests to localhost (unlike the filesystem), but I might be wrong.

这篇关于跨域javascript来访问本地主机。可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆