从外部服务器读取使用脚本src标记调用的文件的响应 [英] Read response of a file called with script src tag from external sever

查看:129
本文介绍了从外部服务器读取使用脚本src标记调用的文件的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,基本上,我们试图从无法控制的外部服务器读取文本或html文件.

So basically we are trying to read a text or html file from external server which we don't have control off .

我们正在使用脚本src标记来获取文件,但无法读取

We are using script src tag to fetch the file but we are unable to read it

<script type="text/css" id="Script1" src="http://www.thirdparty.com/example.txt" ></script>

就像在此屏幕截图中一样,您可以看到我们正在获取随机的txt文件,并且得到了响应,但是通过javascript我们无法读取它.

like in this screenshot you can see we are fetching a random txt file and we are getting a response but through javascript we are unable to read it .

屏幕截图图像链接

所以现在我们的动机是读取example.txt文件并将内容存储到javascript变量中.

So now our motive is to read the example.txt file and store the content into a javascript variables.

我们已经累了,但由于某些或其他原因无法正常工作的事情

Things that we have already tired but didn't work due to some or other reason

  1. 使用XHR和jQuery加载功能

  1. Using XHR and jQuery load function

$(document).ready(function () { $("#container").load("http://www.thirdparty.com/example.txt"); });

$(document).ready(function () { $("#container").load("http://www.thirdparty.com/example.txt"); });

但是正如我所说的,它是第三方服务器,但是我们无法控制它,这是由于跨域XMLHttpRequest导致我们没有从服务器获得任何响应. 顺便说一句,有没有从xhr请求中删除原始标头?

but as I said its third party server and we don't have control over it , that's due to Cross-Origin XMLHttpRequest we are not getting any response from the server. by the way is there anyways to eliminate origin header from the xhr request ?

由于ip问题,无法使用代理服务器,并且需要从客户端发送cookie.

Using proxy server wont work because of ip issue and cookies needs to be send from the client side.

获取script标记的innerhtml和innertext,但是它没有返回响应,而是在标记之间提供了不需要的代码.

Getting innerhtml and innertext of the script tag but it didn't return the response rather it give code between tag which is not required .

P.S.由于某些特定要求,我们基于客户端javascript的解决方案不是基于服务器端的.

P.S. we what something client side javascript bases solution not serverside due to some specific requirements .

提前感谢您的帮助

推荐答案

由于安全原因,这是不可能的.没有,我不再重复在现代浏览器上执行此操作的方法.至少使用JS.您可以使用JAVA,但可能不是您想要的.

It's not possible due to security reasons. There is no, I repeat NO way to do this on modern browsers. At least with JS. You could use JAVA, but it's probably not what You want.

这篇关于从外部服务器读取使用脚本src标记调用的文件的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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