我正在向Bing搜索API發送ajax請求。當我將它放入瀏覽器時,我用於請求的URL有效。隨着阿賈克斯我得到一個401錯誤"The authorization type you provided is not supported. Only Basic and OAuth are supported"
Bing API請求的Ajax授權標頭是什麼?
因此我的頭是錯誤的。它在瀏覽器中工作,因爲我手動輸入了我的天藍色帳戶密鑰。
<script>
$scope.bingsearch = function() {
var azurekey = '....vjrQiHPp4ct1meqroX2pzQZhPvE';
var keywords = $scope.inputvalue;
var myurl = 'https://api.datamarket.azure.com/Bing/Search/v1/Composite?
Sources=%27web%27&$format=json&Query=%27'+ keywords + '%27';
$http({
method: 'POST',
url: myurl,
headers:{
'Authorization': 'Basic ' + azurekey
}
}).success(function(data){
var searchresults = angular.fromJson(+data);
$scope.searchresult = searchresults;
})
};
</script>
URL https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27web%27&$format=json&Query=%27van%20gogh%27
適用於瀏覽器。
如何設置我的標題以便它能接受我的帳戶密鑰?