curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"firstname":"Mike","lastname":"Doel","customer_id":"12345","email":"[email protected]"}' -u API-key: APIURL(http://)
上述聲明是在命令運行良好,但我無法通過PHP代碼才達到相同的下面是我的代碼PHP捲曲,POST JSON得到錯誤的PHP捲曲
$url="https://apiurl";
$data=array("firstname"=>"Mike","lastname"=>"Doel","customer_id"=>"12345","email"=>"[email protected]");
$data_json=json_encode($data);
//Curl code
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"Accept: application/json","api-key"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
已通過任何用戶名或密碼的API密鑰? –
請參閱http://stackoverflow.com/questions/3062324/what-is-curl-in-php –