我正在开发一个基于加密货币的项目,在这个项目中我调用API来获取区块链数据。
所有的API都在工作,但调用这个API https://chainradar.com/api/v1/mro/transactions/e5f456ed51e7eaf548e6e3ceae2a4d50388812e9ada120bffdcda72df43c0ece/full
我收到这个错误
请求的资源上没有“Access-Control-Allow-Origin”标题 跨源读取阻止(CORB)阻止跨源回复https://chainradar.com/api/v1/mro/transactions/e5f456ed51e7eaf548e6e3ceae2a4d50388812e9ada120bffdcda72df43c0ece/full
与MIME类型text / html。
有关更多详细信息,请参见https://www.chromestatus.com/feature/5629709824032768。
我试过使用CORS
节点包,但无法工作。此外,我试图设置标题.htaccess
也无法得到解决。
Angular Code来调用API
angular.module('insight.transactions')
.factory('Transaction',
function($resource) {
return $resource(transactionDetailApi2 + '/:txId/full', {
txId: '@txId'
}, {
get: {
method: 'GET',
interceptor: {
response: function (res) {
return res.data;
// console.log(res);
},
responseError: function (res) {
if (res.status === 404) {
return res;
}
}
}
}
});
});
发布于 2018-06-13 13:34:59
这是一个服务器端问题。你不需要为角色添加任何角度标题。你需要在服务器端添加标题:
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
如果你的API方法也是GET
这样的:
var url = "https://chainradar.com/api/v1/mro/transactions/e5f456ed51e7eaf548e6e3ceae2a4d50388812e9ada120bffdcda72df43c0ece/full";
$http({
method: 'JSONP',
url: url
}).
success(function(status) {
//your code when success
}).
error(function(status) {
//your code when fails
});
https://stackoverflow.com/questions/-100005353
复制相似问题