如何调用中等RSS源 [英] How To Call Medium RSS Feed

查看:74
本文介绍了如何调用中等RSS源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

媒体有 https://medium.com/feed/[@username ] 。我正在尝试使用XMLHTTPRequest获取所有博文。当我在本地测试时,我遇到了CORs错误。当我打开CORs Chrome扩展程序时,出现401错误。有任何想法吗?有没有人成功调用Medium RSS?

Medium has an RSS feed available at https://medium.com/feed/[@username]. I'm trying to fetch all my blog posts using an XMLHTTPRequest. When I test on local, I run into CORs errors. When I turn on CORs Chrome extension, I get a 401 error. Any ideas? Has anyone succeeded in calling Medium RSS?

推荐答案

获取 https://medium.com/feed / [@ username] 使用XHR的内容,您可以通过某种代理发出XHR请求。例如,尝试将此网址提供给您当前的XHR代码:

To get https://medium.com/feed/[@username] content using XHR, you can make the XHR request through a proxy of some kind. For example, trying giving your current XHR code this URL:

https://cors-anywhere.herokuapp.com/https://medium.com/feed/@sideshowbarker

这会导致请求转到 https://cors-anywhere.herokuapp.com ,一个开放/公共CORS代理,然后将请求发送到 https://medium.com/ feed / @ sideshowbarker

That’ll cause the request to go to https://cors-anywhere.herokuapp.com, a open/public CORS proxy which then sends the request on to https://medium.com/feed/@sideshowbarker.

当该代理获得响应时,它接受并添加 Access-Control -Allow-Origin 响应头,然后将其作为响应传递回您的请求前端代码。

And when that proxy gets the response, it takes it and adds the Access-Control-Allow-Origin response header to it and then passes that back to your requesting frontend code as the response.

使用<$的响应c $ c> Access-Control-Allow-Origin 响应头是浏览器看到的内容,因此浏览器显示的错误消息现在消失了,浏览器允许您的前端JavaScript代码访问回复。

That response with the Access-Control-Allow-Origin response header is what the browser sees, so the error message the browser is showing you now goes away, and the browser allows your frontend JavaScript code to access the response.

或者使用 HTTPS:// GIT中hub.com/Rob--W/cors-anywhere/ 等设置您自己的代理。

Or use the code from https://github.com/Rob--W/cors-anywhere/ or such to set up your own proxy.

您需要代理的原因是,回复来自 https://medium.com/feed/ [@username] 不包括 Access-Control-Allow-Origin 响应标头,因此您的浏览器将拒绝让您的前端JavaScript代码访问那些跨源的响应。

The reason you need a proxy is, responses from https://medium.com/feed/[@username] don’t include the Access-Control-Allow-Origin response header, so your browser will refuse to let your frontend JavaScript code access those responses cross-origin.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS 有更多细节。

这篇关于如何调用中等RSS源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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