我正在使用AngularJS和Node.js,我试图从特定网址读取标题 我有这样的事情:
App.config(function($httpProvider) {
//Enable cross domain calls
$httpProvider.defaults.useXDomain = true;
//Remove the header used to identify ajax call that would prevent CORS from working
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
我尝试用以下内容阅读网址标题:
$http({ url:$scope.url,method:"POST", headers: {'Content-Type': 'application/x-www-form- urlencoded'}}).success(function(data){
console.log(data);
});
但我收到NetworkError:405方法不允许和/或阻止跨源请求:....
答案 0 :(得分:2)
客户端代码不重要,您需要在服务器端启用CORS以允许跨源请求。