How To Call Medium RSS Feed

孤人 提交于 2019-12-12 09:46:15

问题


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?


回答1:


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

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.

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.

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.

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

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 has more details.



来源:https://stackoverflow.com/questions/44468743/how-to-call-medium-rss-feed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!