我正在调用Watson的API,如下所示:
$url2 = 'https://watson-api-explorer.mybluemix.net/personality-insights/api/v3/profile?raw_scores=false&csv_headers=false&consumption_preferences=true&version=2017-02-01';
$request_headers = array();
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Content-Type: text/plain';
$request_headers[] = 'Content-Language: en';
$request_headers[] = 'Accept-Language: en';
$simple_data = 'some really interesting text goes here';
$plain_data = json_encode($data);
$ch2 = curl_init( $url2 );
curl_setopt_array( $ch2, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $simple_data,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => $request_headers,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERPWD => 'XXX:YYY' //removed for illustration
)
);
$response2 = curl_exec( $ch2 );
var_dump($response2);这会继续返回错误,如下所示:
{"code":415,"sub_code":"S00002","error":"Unsupported Content-Type: \"application\/x-www-form-urlencoded\""}不知道为什么这篇文章没有被正确发送,以及我需要如何发送它。
发布于 2017-02-21 09:44:33
您应该使用CURLOPT_HTTPHEADER而不是CURLOPT_HEADER来设置请求头。
CURLOPT_HEADER是一个"on/off"-switch,用于设置与请求一起设置的标题。
发布于 2017-02-23 18:05:42
https://watson-api-explorer.mybluemix.net是一个匿名代理,用于具有速率和使用限制的测试目的--编程访问应该使用从Bluemix.net获得的凭据通过https://gateway.watsonplatform.net。
https://stackoverflow.com/questions/42357955
复制相似问题