2017-03-31 69 views
0

我有一个问题与bing新闻搜索api,最奇怪的是按类别搜索,根据文档,该类别必须是一个字符串,我发现多个资源它接受的价值,所以我决定去控制台(https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56b449fbcf5ff81038d15cdf/console)。一旦你选择一个类别并把它放到你的密钥中,它就可以正常工作。 问题是,当我从控制台邮递员复制网址完全相同,我使用相同的密钥和我得到“400错误的请求”头这身搭配:400与bing新闻搜索api的错误

{ 
    "_type": "ErrorResponse", 
    "errors": [ 
    { 
     "code": "RequestParameterInvalidValue", 
     "message": "Parameter has invalid value.The category parameter is invalid.", 
     "parameter": "category", 
     "value": "Entertainment" 
    } 
    ] 
} 

任何知道我做错了这里?

回答

0

这里是一个非常哈克解决方法: 因为请求通过开发者控制台工作正常,我检查的要求,并试图repeate它认为卷曲,似乎工作正常,命令如下:

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”, “宿主”: “api.cognitive.microsoft.com”, “方案” :“https”,“路径”:“bing/v5.0/news /?Category = Entertainment”, “headers”:[{“name”:“Host”,“value”: “api.cognitive.microsoft.com”,“inputTypeValue”:“text”, “reveal”:false,“options”:null ,“required”:true, “readonly”:true,“custom”:false},{“name”: “Ocp-Apim-Subscription-Key”,“value”:“”, “inputTypeValue”密码“,”显示“:假,”选项“:[], ”required“:true,”readonly“:false,”custom“:true,”secret“: true}], “name”:“Category”,“value”: “Entertainment”,“inputType”:“text”,“required”:false, “options”:[“Business”,“Entertainment”政治学“, ”科学与技术“,”体育“,”美国/英国“,”世界“],”风俗“: fal se,“description”:“

指定呼叫者想要返回哪类新闻文章 。

\ n”, “的typeName”: “串”}], “体”: “”}

我会记住这是正确的,现在因为我无法找到任何其他解决方案