首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >沃森返回415错误

沃森返回415错误
EN

Stack Overflow用户
提问于 2017-02-21 03:12:27
回答 2查看 177关注 0票数 0

我正在调用Watson的API,如下所示:

代码语言:javascript
复制
$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);

这会继续返回错误,如下所示:

代码语言:javascript
复制
{"code":415,"sub_code":"S00002","error":"Unsupported Content-Type: \"application\/x-www-form-urlencoded\""}

不知道为什么这篇文章没有被正确发送,以及我需要如何发送它。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-21 09:44:33

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

CURLOPT_HEADER是一个"on/off"-switch,用于设置与请求一起设置的标题。

票数 2
EN

Stack Overflow用户

发布于 2017-02-23 18:05:42

https://watson-api-explorer.mybluemix.net是一个匿名代理,用于具有速率和使用限制的测试目的--编程访问应该使用从Bluemix.net获得的凭据通过https://gateway.watsonplatform.net

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42357955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档