我正在尝试在 php 中使用 Watson 概念扩展服务。
我正在使用以下代码上传种子列表-
<?php
header('Content-type: application/json');
$services_json = json_decode(getenv('VCAP_SERVICES'), true);
$cred = $services_json["concept_expansion"][0]["credentials"];
// credentials
$username = $cred["username"];
$password = $cred["password"];
$url = $cred["url"] . '/v1/upload';
$auth = base64_encode($username . ":" . $password);
try {
//List of terms to seed the concept expansion.
$temp = array('seeds' => array('motrin','aspirin','keflex' ) );
$data = array(
'seeds' => $temp,
'dataset' => 'mtsamples',
'label' => 'drugs' // label for the seeds
);
$data_string = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'X-synctimeout: 30',
'Authorization: Basic ' . $auth)
);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
echo $result;
} catch(Exception $e) {
echo $e->getMessage();
}
?>
但是代码给出了 400 错误。我有什么遗漏吗?