【问题标题】:Basic Authentication of Bing Search API必应搜索 API 的基本身份验证
【发布时间】:2016-07-22 21:08:26
【问题描述】:

我读过这篇文章: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); 
        }
        });

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

【问题讨论】:

    标签: json azure bing bing-api bing-search


    【解决方案1】:

    如果我理解正确,您正在尝试为您的呼叫做一些类似代理.. 但是您没有正确设置您的 HTTP 标头字段,就像您的 php 文件从 api.datamarket.azure.com 接收的一样,所以您需要要设置这些,请参阅 answer 并正确设置 HTTP 标头,并按照 here 所述进行 ajax 调用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 2013-06-28
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      相关资源
      最近更新 更多