[英]AngularJs and Bluemix QA API can't make a post request
我正在嘗試將Angular應用程序連接到Bluemix QA API。 所以我有這段代碼。
$http({
method: 'POST',
url: 'https://gateway.watsonplatform.net/question-and-answer-beta/api/v1/question/healthcare',
headers: {
'Content-Type': 'application/json',
'Authorization':'Basic mytoken',
'X-SyncTimeout': 30
},
data: {
'question': {
'questionText': 'Malaria?'
}
}
}).then(function(response){
$scope.response = JSON.stringify(response);
});
我的app.js上也有這個
.config([
'$routeProvider',
'$httpProvider',
function($routeProvider, $httpProvider){
$httpProvider.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
$httpProvider.defaults.headers.common['Access-Control-Allow-Headers'] = '*';
}])
但是,當我嘗試運行該方法時,出現此錯誤:
Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers.
如果我嘗試刪除標頭,則會在另一個標頭中給我一個問題。 那么,有什么想法嗎? 還是任何ajax示例? 我知道有一些nodejs示例,但是我想知道是否可以直接連接到api。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.