我正在构建一个 Web 应用程序并希望集成 IBM Watson Personality Insights API。我正在使用 PHP,并且必须使用 Curl Library 来做同样的事情
以下是 IBM 文档中提到的使用 Curl 的代码
curl -X POST --user {username}:{password}
--header "Content-Type: text/plain;charset=utf-8"
--header "Accept: application/json"
--data-binary @<filename>
"https://gateway.watsonplatform.net/personality-insights/api/v3/profile"
我如何在 PHP 中做到这一点?
我正在尝试这样做,但我得到一个空洞的回应
$ch2 = curl_init("https://gateway.watsonplatform.net/personality-insights/api/v3/profile");
$request_headers = array();
$request_headers[] = 'Content-Type: text/plain;charset=utf-8';
$request_headers[] = 'Content-Language: en';
$request_headers[] = 'Accept-Language: en';
$simple_data = 'Some dummy data';
curl_setopt_array( $ch2, array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $simple_data,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_USERPWD => 'XXXX:YYYY',
)
);
$response2 = curl_exec( $ch2 );