bing 新闻搜索 api 出现 400 错误
400 error with bing news search api
我在 bing 新闻搜索 api 中遇到了一些问题,最奇怪的是按类别搜索,根据文档,类别必须是一个字符串,我发现它接受多个资源的值,所以我决定使用控制台 (https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56b449fbcf5ff81038d15cdf/console)。一旦你 select 一个类别并将其放入你的密钥,它就可以正常工作。
问题是当我将完全相同的 URL 从控制台复制到邮递员时,我使用相同的密钥并且我得到“400 Bad Request”header body:
{
"_type": "ErrorResponse",
"errors": [
{
"code": "RequestParameterInvalidValue",
"message": "Parameter has invalid value.The category parameter is invalid.",
"parameter": "category",
"value": "Entertainment"
}
]
}
知道我做错了什么吗?
这是一个非常 Hacky 的解决方法:
由于请求通过开发者控制台工作正常,我检查了请求并尝试重复它认为 curl,似乎工作正常,命令如下:
curl 'https://dev.cognitive.microsoft.com/console/query' -H 'Content-Type: application/json' --data-binary '{"httpMethod":"GET","host":"api.cognitive.microsoft.com","scheme":"https","path":"bing/v5.0/news/?Category=Entertainment","headers":[{"name":"Host","value":"api.cognitive.microsoft.com","inputTypeValue":"text","revealed":false,"options":null,"required":true,"readonly":true,"custom":false},{"name":"Ocp-Apim-Subscription-Key","value":"<your key value>","inputTypeValue":"password","revealed":false,"options":[],"required":true,"readonly":false,"custom":true,"secret":true}],"parameters":[{"name":"Category","value":"Entertainment","inputType":"text","required":false,"options":["Business","Entertainment","Health","Politics","ScienceAndTechnology","Sports","US/UK","World"],"custom":false,"description":"<p>Specifies which category of news articles the caller wants returned.</p>\n","typeName":"string"}],"body":""}'
我发送的json数据是这个(从上面的命令复制过来的)
{ "httpMethod": "GET", "host": "api.cognitive.microsoft.com",
"scheme": "https", "path": "bing/v5.0/news/?Category=Entertainment",
"headers": [{ "name": "Host", "value":
"api.cognitive.microsoft.com", "inputTypeValue": "text",
"revealed": false, "options": null, "required": true,
"readonly": true, "custom": false }, { "name":
"Ocp-Apim-Subscription-Key", "value": "",
"inputTypeValue": "password", "revealed": false, "options": [],
"required": true, "readonly": false, "custom": true, "secret":
true }], "parameters": [{ "name": "Category", "value":
"Entertainment", "inputType": "text", "required": false,
"options": ["Business", "Entertainment", "Health", "Politics",
"ScienceAndTechnology", "Sports", "US/UK", "World"], "custom":
false, "description": "
Specifies which category of news articles
the caller wants returned.
\n", "typeName": "string" }],
"body": "" }
我暂时将其标记为正确,因为我找不到任何其他解决方案
我在 bing 新闻搜索 api 中遇到了一些问题,最奇怪的是按类别搜索,根据文档,类别必须是一个字符串,我发现它接受多个资源的值,所以我决定使用控制台 (https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56b449fbcf5ff81038d15cdf/console)。一旦你 select 一个类别并将其放入你的密钥,它就可以正常工作。 问题是当我将完全相同的 URL 从控制台复制到邮递员时,我使用相同的密钥并且我得到“400 Bad Request”header body:
{
"_type": "ErrorResponse",
"errors": [
{
"code": "RequestParameterInvalidValue",
"message": "Parameter has invalid value.The category parameter is invalid.",
"parameter": "category",
"value": "Entertainment"
}
]
}
知道我做错了什么吗?
这是一个非常 Hacky 的解决方法: 由于请求通过开发者控制台工作正常,我检查了请求并尝试重复它认为 curl,似乎工作正常,命令如下:
curl 'https://dev.cognitive.microsoft.com/console/query' -H 'Content-Type: application/json' --data-binary '{"httpMethod":"GET","host":"api.cognitive.microsoft.com","scheme":"https","path":"bing/v5.0/news/?Category=Entertainment","headers":[{"name":"Host","value":"api.cognitive.microsoft.com","inputTypeValue":"text","revealed":false,"options":null,"required":true,"readonly":true,"custom":false},{"name":"Ocp-Apim-Subscription-Key","value":"<your key value>","inputTypeValue":"password","revealed":false,"options":[],"required":true,"readonly":false,"custom":true,"secret":true}],"parameters":[{"name":"Category","value":"Entertainment","inputType":"text","required":false,"options":["Business","Entertainment","Health","Politics","ScienceAndTechnology","Sports","US/UK","World"],"custom":false,"description":"<p>Specifies which category of news articles the caller wants returned.</p>\n","typeName":"string"}],"body":""}'
我发送的json数据是这个(从上面的命令复制过来的)
{ "httpMethod": "GET", "host": "api.cognitive.microsoft.com", "scheme": "https", "path": "bing/v5.0/news/?Category=Entertainment", "headers": [{ "name": "Host", "value": "api.cognitive.microsoft.com", "inputTypeValue": "text", "revealed": false, "options": null, "required": true, "readonly": true, "custom": false }, { "name": "Ocp-Apim-Subscription-Key", "value": "", "inputTypeValue": "password", "revealed": false, "options": [], "required": true, "readonly": false, "custom": true, "secret": true }], "parameters": [{ "name": "Category", "value": "Entertainment", "inputType": "text", "required": false, "options": ["Business", "Entertainment", "Health", "Politics", "ScienceAndTechnology", "Sports", "US/UK", "World"], "custom": false, "description": "
Specifies which category of news articles the caller wants returned.
\n", "typeName": "string" }], "body": "" }
我暂时将其标记为正确,因为我找不到任何其他解决方案