以下代码非常简单。但是,当我执行它时,我总是从Watson-Conversation服务获得 {“error”:“Unsupported Media Type”} 。请帮助告诉我问题的来源。
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_POST => true,
CURLOPT_URL => "https://watson-api-explorer.mybluemix.net/conversation/api/v1/workspaces/70b056e6-14a0-424f-9631-696272ce666e/message?version=2016-09-20",
CURLOPT_USERPWD => "{MYUSERNAME}:{MYPASSWORD}",
CURLOPT_POSTFIELDS => array('message' => '{ "input": { "text": "Hola" }, "alternate_intents": false }'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err)
{
echo "cURL Error #:" . $err;
}
else
{
echo $response;
}
非常感谢。
答案 0 :(得分:3)
我已通过在通话中添加以下选项将其整理出来:
CURLOPT_HTTPHEADER => array('Content-Type: application/json')