Reputation: 69
The following code is very straightforward. However, when I execute it, I always get {"error":"Unsupported Media Type"} from Watson-Conversation service. Please help to show me where the issue comes from.
$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;
}
Thank you very much.
Upvotes: 1
Views: 816
Reputation: 69
I have sorted it out already by adding following option into the call:
CURLOPT_HTTPHEADER => array('Content-Type: application/json')
Upvotes: 5