我对bing news search api有几个问题,最奇怪的是按类别搜索,根据文档,类别必须是一个字符串,我找到了多个资源,它接受的值是这样的我决定使用控制台(https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56b449fbcf5ff81038d15cdf/console)。一旦你选择了一个类别并把它作为你的密钥,它就可以了。 问题是当我将完全相同的URL从控制台复制到邮递员时,我使用相同的密钥,然后我得到错误请求" 400 Bad Request"这个身体的标题:
{
"_type": "ErrorResponse",
"errors": [
{
"code": "RequestParameterInvalidValue",
"message": "Parameter has invalid value.The category parameter is invalid.",
"parameter": "category",
"value": "Entertainment"
}
]
}
知道我在这里做错了什么?
答案 0 :(得分:0)
这是一个非常Hacky的解决方法: 由于请求通过开发人员控制台工作正常,我检查了请求,并试图重复它认为卷曲,似乎工作正常,命令如下:
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数据是这个(从上面的命令复制)
{&#34; httpMethod&#34;:&#34; GET&#34;,&#34; host&#34;:&#34; api.cognitive.microsoft.com&#34;, &#34;计划&#34;:&#34; https&#34;,&#34;路径&#34;:&#34; bing / v5.0 / news /?类别=娱乐&#34;, &#34;标题&#34;:[{&#34; name&#34;:&#34; Host&#34;,&#34; value&#34;: &#34; api.cognitive.microsoft.com&#34;,&#34; inputTypeValue&#34;:&#34; text&#34;, &#34;透露&#34;:false,&#34;选项&#34;:null,&#34; required&#34;:true, &#34; readonly&#34;:true,&#34; custom&#34;:false},{&#34; name&#34;: &#34; Ocp-Apim-Subscription-Key&#34;,&#34; value&#34;:&#34;&#34;, &#34; inputTypeValue&#34;:&#34;密码&#34;,&#34;显示&#34;:false,&#34;选项&#34;:[], &#34;必需&#34;:true,&#34; readonly&#34;:false,&#34; custom&#34;:true,&#34; secret&#34;: true}],&#34;参数&#34;:[{&#34; name&#34;:&#34; Category&#34;,&#34; value&#34;: &#34;娱乐&#34;,&#34; inputType&#34;:&#34; text&#34;,&#34; required&#34;:false, &#34;选项&#34;:[&#34; Business&#34;,&#34; Entertainment&#34;,&#34; Health&#34;,&#34; Politics&#34;, &#34; ScienceAndTechnology&#34;,&#34; Sports&#34;,&#34; US / UK&#34;,&#34; World&#34;],&#34; custom&#34;: false,&#34; description&#34;:&#34;
指定哪类新闻文章 调用者想要返回。
\ n&#34;,&#34; typeName&#34;:&#34; string&#34; }], &#34;身体&#34;:&#34;&#34; }
我现在将此标记为正确,因为我无法找到任何其他解决方案