I need to recreate this in PHP:
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"
I've got this:
$request_headers = array();
$request_headers[] = 'Content-Type: text/plain;charset=utf-8';
$request_headers[] = 'Content-Language: en';
$request_headers[] = 'Accept-Language: en';
$simple_data = 'washingtonpost by the intelligence community';
curl_setopt_array( $ch2, array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $simple_data,
CURLOPT_HEADER => $request_headers,
CURLOPT_USERPWD => 'XXXX:YYYY',
)
);
$response2 = curl_exec( $ch2 );
What my code doesn't account for is the --data-binary
part, but I'm not sure how to "translate" this into PHP. In addition, can I use data binary with plain text (the API accepts it) instead of JSON?