无效的请求:内容为空

时间:2019-06-20 17:12:03

标签: curl ibm-watson watson-nlu

我只是从cURL开始,我正在使用Watson自然语言理解(NLU)服务。.下一行给我错误代码:400“无效的请求,内容为空”

注意:我是Windows用户

非常感谢您的帮助!

我要做的就是这个简单的入门示例

https://cloud.ibm.com/services/natural-language-understanding/crn:v1:bluemix:public:natural-language-understanding:us-south:a%2f1fdc918bf6c243fcb853ba8fb6907839:aaf7bfd6-ca63-431a-a143-e2cc863ebc6c::?paneId=gettingStarted

curl -X POST -u "apikey:{MY_API_KEY}" ^
"https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-11-16" ^

1 个答案:

答案 0 :(得分:1)

嘿@mohsen上面的Post请求中缺少主体,一个示例请求看起来像这样的文本关键字,还替换了以下curl请求中的API-KEY。在公共站点上发布API密钥不是理想的选择

curl -X POST \
 'https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-01-11' \
-u "apikey:<API-KEY>"\
 -H 'Content-Type: application/json' \
 -H 'cache-control: no-cache' \
 -d '{
   "text":"Iran Warns Of Retaliation If U.S. Breaches Nuclear Deal. Iran Supreme Leader Ayatollah Khamenei is warning that Tehran will retaliate if the sanctions are approved.",
   "features": {
       "keywords":{
           "sentiment":true

       }
   },
   "language":"en"

}'