我试图进入 PHP 这个卷曲:
curl -X POST -u "apikey:MY_API_KEY" \
--header "Content-Type: text/plain;charset=utf-8" \
--header "Accept: application/json" \
--data-binary "MY_TEXT" \
"https://MY_DIRECTION"
到目前为止,我想出了这个:
$curl = curl_init();
$post_args = array('data-binary' => $MY_TEXT );
$header_args = array(
'Content-Type: text/plain;charset=utf-8',
'Accept: application/json'
);
$apiKey = '$MY_API_KEY';
$api_args = array('apikey: ' . $apiKey);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $api_args);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_args);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_args);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_URL, $MY_DIRECTION);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
json_decode($result, true);
我正在尝试使用 IBM 的 Personality Insights 服务。
守着一只汪