最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Enabling CORS for accessing remote feed - Stack Overflow

programmeradmin2浏览0评论

I'm trying to read a remote RSS feed and getting the follwing error message:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://*.*.*.*' is therefore not allowed access.

Can anyone tell me how to enable CORS so I can resolve this issue - particularly if I don't have admin access to the remote resource?

I'm trying to read a remote RSS feed and getting the follwing error message:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://*.*.*.*' is therefore not allowed access.

Can anyone tell me how to enable CORS so I can resolve this issue - particularly if I don't have admin access to the remote resource?

Share Improve this question asked Feb 9, 2014 at 7:50 siskosisko 9,94020 gold badges74 silver badges142 bronze badges 3
  • What host provider you are using? I think you need to add that header settings into Apache/IIS. – Panu Oksala Commented Feb 9, 2014 at 7:54
  • 1 CORS is a mechanism for the owner of a resource to allow other origins to access it. If you don't own the resource, you can't enable CORS. You can set up a proxy server that fetches the resource and delivers it to the browser on an allowed origin. – apsillers Commented Feb 9, 2014 at 7:57
  • possible duplicate of Access Control Allow Origin not allowed by – Ray Nicholus Commented Feb 9, 2014 at 14:16
Add a ment  | 

2 Answers 2

Reset to default 3

It's up to the remote resource to allow cross-origin resource sharing. The response needs to have a header that specifies that access can e from your domain. Something like:

Access-Control-Allow-Origin: http://xyz.example.

needs to be present in the response headers.

Without control over what the remote site, there's not much you can do to enable CORS to that site (other than contacting the site administrator).

Other CORS headers and how the entire scheme works is described here (among other places).

Seems like a cross domain request issue. Would you consider just using a middle scrit as a proxy workaround? Then make your javascript request to a php file that grabs the data for and feeds it back such as

<?php
$url = 'http://getmethedatafromyourapi';

header('Content-Type:text/json');
echo file_get_contents($url);
发布评论

评论列表(0)

  1. 暂无评论