我需要在PHP中重新創建此:譯「數據的二進制」從捲曲到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"
我有這樣的:
$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);
我的代碼不佔什麼--data-binary
部分,但我不確定如何將其「翻譯」爲PHP。另外,我可以使用純數據的二進制數據(API接受它)而不是JSON嗎?
在你的代碼中,'CURLOPT_HEADER'應該是'CURLOPT_HTTPHEADER'來設置請求頭。否則,POSTFIELDS與自定義Content-Type一樣正確。 – drew010
@ drew010這正是問題!謝謝!如果您提交答案,我可以接受。欣賞它。 – jonmrich