0
我正在嘗試使用角度1.4.7創建一個跨域請求。我對這個主題很新,特別是在這種情況下,我無法通過谷歌找到任何幫助。基於角度令牌的基於身份驗證的驗證
環境: 我嘗試從www.a.com服務的角度應用程序A調用由www.b.com服務的服務器B提供的restful api。
我苦苦掙扎的事情是,我必須在http文章中爲自己授權一個via標記。此令牌constelation應該是這樣的:
{
"account": {
"hashcode": "somehashcode"
},
"hashkey": "somehashkey"
};
我測試了郵遞員的API的效果很好,但我沒有用角去實現它。
postman successful try picture 1 postman successful try picture 2
要啓用CORS在我app.js:
.config(['$httpProvider', function($httpProvider){
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common["X-Requested-With"];
}]);
的我的要求:
$http({
url: 'http://evori-api.azurewebsites.net/api/handshake',
method: 'POST',
data: authtoken,
headers: {
'Content-Type': 'application/json'
}
})
.then(function(data, status) {
console.log(data + status);
}, function() {
});
任何幫助,將不勝感激。即使你剛剛拿到一篇文章或博客,解釋應該如何做這些事情。我知道這可能只是一個愚蠢的錯誤或某事,但它使我發瘋。
非常感謝。