Bing 搜索的基本身份验证 API
Basic Authentication of Bing Search API
我读过这个post:Bing search API and Azure
我用下面的代码来模仿它:
<?php
if (isset($_GET['bingquery'])){
// Replace this value with your account key
$accountKey = '***myaccountkey***';
$WebSearchURL = 'https://api.datamarket.azure.com/Bing/Search/v1/' + 'News?$format=json&Query=';
$cred = sprintf('Authorization: Basic %s', base64_encode($accountKey . ":" . $accountKey) );
$context = stream_context_create(array(
'http' => array(
'header' => $cred
)
));
$request = $WebSearchURL . urlencode( '\'' . $_GET["bingquery"] . '\'');
$response = file_get_contents($request, 0, $context);
echo $response;
}
?>
我的 AJAX 电话是:
var bingquery = "bingquery=" + $('#query').val();
$.ajax({
url: "bingsearch.php",
method: "get",
dataType: "json",
data: bingquery,
success: function(jsondata){
console.log(jsondata);
}
});
但是,我仍然无法从 Bing 搜索中取回 JSON 格式的数据,有什么建议吗?非常感谢您的帮助!
我读过这个post:Bing search API and Azure
我用下面的代码来模仿它:
<?php
if (isset($_GET['bingquery'])){
// Replace this value with your account key
$accountKey = '***myaccountkey***';
$WebSearchURL = 'https://api.datamarket.azure.com/Bing/Search/v1/' + 'News?$format=json&Query=';
$cred = sprintf('Authorization: Basic %s', base64_encode($accountKey . ":" . $accountKey) );
$context = stream_context_create(array(
'http' => array(
'header' => $cred
)
));
$request = $WebSearchURL . urlencode( '\'' . $_GET["bingquery"] . '\'');
$response = file_get_contents($request, 0, $context);
echo $response;
}
?>
我的 AJAX 电话是:
var bingquery = "bingquery=" + $('#query').val();
$.ajax({
url: "bingsearch.php",
method: "get",
dataType: "json",
data: bingquery,
success: function(jsondata){
console.log(jsondata);
}
});
但是,我仍然无法从 Bing 搜索中取回 JSON 格式的数据,有什么建议吗?非常感谢您的帮助!