在我的bing定制搜索API上提交搜索时,返回404找不到。

我已将API密钥和端点更改为我的详细信息
我的端点是:https://fruitbox-search.cognitiveservices.azure.com/bing/v7.0

// Replace with a valid subscription key from your Azure account.

$accessKey = 'MY-KEY-HERE';
$endpoint = 'https://fruitbox-search.cognitiveservices.azure.com/bing/v7.0';
$term = 'Microsoft Cognitive Services';

function BingWebSearch ($url, $key, $query) {
   /*
    * Prepare the HTTP request.
    * NOTE: Use the key 'http' even if you are making an HTTPS request.
    * See: http://php.net/manual/en/function.stream-context-create.php.
    */
    $headers = "Ocp-Apim-Subscription-Key: $key\r\n";
    $options = array ('http' => array (
                          'header' => $headers,
                           'method' => 'GET'));

    // Perform the request and receive a response.
    $context = stream_context_create($options);
    $result = file_get_contents($url . "?q=" . urlencode($query), false, $context);

    // Extract Bing HTTP headers.
    $headers = array();
    foreach ($http_response_header as $k => $v) {
        $h = explode(":", $v, 2);
        if (isset($h[1]))
            if (preg_match("/^BingAPIs-/", $h[0]) || preg_match("/^X-MSEdge-/", $h[0]))
                $headers[trim($h[0])] = trim($h[1]);
    }

    return array($headers, $result);
}

我的控制台出现以下错误:

GET https://fruitbox-search.cognitiveservices.azure.com/bing/v7.0?q=test&mkt=en-US&SafeSearch=strict&promote=webpages&answerCount=9&count=25&offset=0&textDecorations=true&textFormat=HTML 404(找不到资源)-VM523:1

拒绝获取不安全的 header “BingAPIs-TraceId”-script.js:264

最佳答案

我已经解决了,解决方案如下:

我必须将端点设置为:
https://fruitbox-search.cognitiveservices.azure.com/bing/v7.0/search

最后缺少/ search。

关于javascript - 找不到返回404的Bing Web搜索API GET请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57694921/

10-13 00:42