从本地文件跨产地GET://产地、本地文件、GET

2023-09-10 21:22:03 作者:23.欢囍

我试图建立一个HTML文件,以监视远程定点有些东西特别,github.com。我希望能够保持它只是平面文件,使得请求直接从JS到GitHub的API。我的思考过程是这样的:

I'm trying to build an html file to monitor some things on a remote site- specifically, github.com. I'd like to be able to keep it to just that flat file, making the requests straight from the JS to github's API. My thought process went like this:

让我们使用JSONP,因为我只需要读访问,所以与坚持获得应该罚款。 失败,因为你can't做基本的身份验证JSONP 。 Let's use jsonp, since I only need read access, so sticking with GETs should be fine. That fails because you can't do basic authentication with jsonp. 失败,因为浏览器不喜欢我重定向到一个本地资源:不允许加载本地资源:文件:///用户/ ... 的可以理解的安全原因。 That fails because the browser doesn't like me redirecting to a local resource: Not allowed to load local resource: file:///Users/... for understandable security reasons. 失败,因为你显然不能访​​问任何关于孩子的iframe,如果它是另一个域,所以,除非我重定向到文件:///什么的,我不能得到最终的URL。而且,当然,我不能重定向到文件:///什么,因为`不允许加载本地资源再次的 从文件中失败,因为CORS:/// URL发送起源头为空,which服务器将不接受

所以,任何建议,如何成功地从一个单一的,本地HTML验证到这个API文件 - 无论是作为围绕上述触点的方式,或者其他的想法完全?

So, any suggestions as to how to successfully authenticate to this api from a single, local html file- either as a way around the above tacts, or another idea entirely?

推荐答案

如果您使用的是谷歌浏览器,你可以尝试用它运行在

If you are using google chrome you could try running it with the

- 让文件存取的档案

切换功能。