【发布时间】:2016-08-29 17:04:25
【问题描述】:
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"firstname":"Mike","lastname":"Doel","customer_id":"12345","email":"test_api_user@gmail.com.com"}' -u API-key: APIURL(http://)
上面的语句在命令中运行良好,但我无法通过 php 代码实现同样的效果,下面是我的代码
$url="https://apiurl";
$data=array("firstname"=>"Mike","lastname"=>"Doel","customer_id"=>"12345","email"=>"test_api_user@gmail.com");
$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 密钥传递了任何用户 ID 或密码?