Php 沃森返回415错误

Php 沃森返回415错误,php,ibm-cloud,ibm-watson,watson,Php,Ibm Cloud,Ibm Watson,Watson,我正在调用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

我正在调用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\""}

不确定为什么无法正确发送此文本以及我需要如何发送。

您应该使用CURLOPT_HTTPHEADER而不是CURLOPT_HEADER来设置请求头


CURLOPT_HEADER是一个“开/关”开关,用于设置与请求一起或不一起设置的头。

您应该使用CURLOPT_HTTPHEADER而不是CURLOPT_HEADER来设置请求头


CULLOPT_标题为“开/关”-切换要与请求一起设置或不一起设置的头。

是一个匿名代理,用于具有速率和使用限制的测试目的--编程访问应使用从Bluemix.net获得的凭据进行。

是一个匿名代理,用于具有速率和使用限制的测试目的--编程访问应使用从Bluemix.net获得的凭据。

来自watson的错误是,帖子发送的标题带有不受支持的
应用程序/x-www-form-urlencoded
。你确定一篇文章应该有效吗?沃森的错误是,该文章发送的标题中包含不受支持的
应用程序/x-www-form-urlencoded
。你确定一个帖子应该有用吗?