简体   繁体   English

XMLHttpRequest无法加载 <instagram OEMBED URL> 。 请求的资源上不存在“ Access-Control-Allow-Origin”标头

[英]XMLHttpRequest cannot load <instagram OEMBED URL>. No 'Access-Control-Allow-Origin' header is present on the requested resource

i am developing OEMBED app where i want to request some OEMBED api to get me JSON data. 我正在开发OEMBED应用,我想请求一些OEMBED API来获取JSON数据。 I am using node/ express in backend and angular in front end. 我在后端使用node / express,在前端使用angular。

Here is my server code. 这是我的服务器代码。

 var express = require("express"); var app =express(); var allowCrossDomain = function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); // intercept OPTIONS method if ('OPTIONS' == req.method) { res.send(200); } else { next(); } }; app.use(allowCrossDomain); app.use(express.static(__dirname + '/js')); app.get('/',function(req,res,next){ res.sendfile('index.html'); }); app.listen(3000,function(){ console.log("We are listening at 3000"); }); 

and my angular code 和我的角度代码

 app.controller('status_controller',function($scope,$http){ $scope.add_status=function(){ $http.get("http://api.instagram.com/oembed?url=http://instagram.com/p/V8UMy0LjpX/&format=json").success(function(data){ console.log(data); }); }; }); 

After executing i am getting this error in console. 执行后,我在控制台中收到此错误。

 XMLHttpRequest cannot load http://api.instagram.com/oembed? url=http://instagram.com/p/V8UMy0LjpX/&format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://<<localhost>>:3000' is therefore not allowed access. 

I have tried node package such as cors and express-cors and i also tried suggestion from similiar post in SO but nothing helps me. 我尝试了诸如cors和express-cors之类的节点程序包,也尝试了SO类似文章中的建议,但没有任何帮助。

I know i have to do something with CORS but don't know how. 我知道我必须对CORS做些事情,但不知道如何做。

i am using chrome and localhost development environment. 我正在使用chrome和localhost开发环境。

If you using AngularJS<1.2 you need to delete the 'X-Requested-With' header and set useXDomain to true in order to make it work 如果您使用的是AngularJS <1.2,则需要删除“ X-Requested-With”标头,并将useXDomain设置为true才能使其正常工作

yourModule
  .config(function($httpProvider){
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
});

otherwise this is not required in higher versions. 否则,在更高版本中不需要。 The server needs to setup with the crossDomain stuff ie the instagram one (and not your local server) 服务器需要设置crossDomain的东西,即instagram的东西(而不是您的本地服务器)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XMLHttpRequest无法加载[archivo]。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 起源[dominio] - XMLHttpRequest cannot load [archivo]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin [dominio] XMLHttpRequest无法加载。 请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许原点访问 - XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access 在本地主机上的请求资源上不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource on localhost No 'Access-Control-Allow-Origin' header is present on the requested resource error - No 'Access-Control-Allow-Origin' header is present on the requested resource error Runkit-请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Runkit - No 'Access-Control-Allow-Origin' header is present on the requested resource 出现错误无法加载资源:请求的资源上不存在“ Access-Control-Allow-Origin”标头 - getting error Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource 错误XMLHttpRequest无法加载不存在“ Access-Control-Allow-Origin”标头。 起源为空 - Error XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present. Origin 'null' AngularJS XMLHttpRequest无法加载X。不存在“ Access-Control-Allow-Origin”标头 - AngularJS XMLHttpRequest cannot load X. No 'Access-Control-Allow-Origin' header present Phonegap请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许原点&#39;null&#39;访问 - Phonegap No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 AngularJS - No 'Access-Control-Allow-Origin' header is present on the requested resource. AngularJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM