我正在向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
适用于浏览器。
如何设置我的标题以便它能接受我的帐户密钥?