我有一些开发人员提供的curl命令,我需要知道如何在PHP中调用它。
命令为:
curl -H "x-api-key: xxxxxxxxxxxxxxxxxxxxxx"
"https://api.civicengine.com/office-
holders?address=1060+W+Addison+Chicago+IL"
我写了这个
$data['api-key']='xxxxxxxxxxxxxxxxxxxxx';
/*$data['host']='https://api.civicengine.com';*/
$url='https://api.civicengine.com/office-holders?address=1060+W+Addison+Chicago+IL';
$ch = curl_init();
// set basic auth
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// set header accept
$headers = array('Accept:application/json', 'Accept-Language:en_US',"Authorization: Bearear xxxxxxxxxxxxxxxxxxxx");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// set mode to POST
curl_setopt($ch, CURLOPT_POST, 1);
// add post fields (1)
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $url);
// Execute
print_r($result = json_decode(curl_exec($ch)));die;
我期待结果,但它的给予
stdClass Object([message] =〉授权标头需要'Credential'参数。授权标头需要'Signature'参数。授权标头需要'SignedHeaders'参数。授权标头需要存在'X-Amz-Date'或'Date'标头。授权= FLUdjGvxuJ 9 liutivB 0 Ll 5LW 2 t2 xmv 31 lvK 2guQi)
2条答案
按热度按时间wz8daaqr1#
你忘记添加
x-api-key
头到你的php curl_ code.还有你的php代码正在改变Accept
Accept-Language
,和Authorization
头,你的curl调用证明这是不需要的,并且他们可能是不正确的 Boot (idk),摆脱他们while debugging(并且一旦一切都工作,你可以添加他们回来并且检查他们不打破任何东西..)7xllpg7q2#
按照此方法发送API REQUEST头中的API_key