javascript - Bing Web Search API GET 请求返回 404 未找到
问题描述
在我的 bing 自定义搜索 API 上提交搜索时,它返回 404 not found。
我已将 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);
}
我在控制台中收到以下错误:
获取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
拒绝获取不安全的标头“BingAPIs-TraceId”-script.js:264
解决方案
我已经解决了这个问题,解决方案如下:
我必须将端点设置为: https ://fruitbox-search.cognitiveservices.azure.com/bing/v7.0/search
最后缺少 /search 。
推荐阅读
- reactjs - 反应布局组件在反应路由器中渲染特定路由
- java - 有人对“==”和“.equals()”的区别有解释吗?在下面的代码中?
- javascript - Chart.js 使用外部 json 文件中某些数据的值
- python - 如何通过在 Python 中遍历数据框中的每一行来将计算值存储在新列中?
- javascript - 在地图内循环
- reactjs - 当我运行 npm run test 时,Jest 遇到了一个意外的令牌
- python - 通过python脚本更新mysql表
- python - 部署到谷歌云平台时遇到问题
- javascript - Jquery在按下按钮时为动画选择下一个eq(i + 1)
- react-native - 有没有一种方法可以隐藏多个文本输入组件在本机反应