Json Bing搜索API的基本身份验证

Json Bing搜索API的基本身份验证,json,azure,bing,bing-api,bing-search,Json,Azure,Bing,Bing Api,Bing Search,我读过这篇文章: 我用下面的代码来模拟它: <?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

我读过这篇文章:

我用下面的代码来模拟它:

<?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;

} 
?>

但是,我仍然无法从Bing搜索中获取JSON格式的数据,有什么建议吗?非常感谢你的帮助

如果我理解正确的话,您正在尝试为您的通话制作类似的代理。。但是,您没有像php文件从api.datamarket.azure.com接收到的那样正确设置HTTP头字段,因此您需要设置这些字段。请参阅此内容,正确设置HTTP头,并进行所述的ajax调用

var bingquery = "bingquery=" + $('#query').val();

    $.ajax({
        url: "bingsearch.php",
        method: "get",
        dataType: "json",
        data: bingquery,
        success: function(jsondata){
            console.log(jsondata); 
        }
        });