我已经与物流公司建立了一个电子商务平台的集成,并且为了获取某些交货数据,需要向API发送POST请求。该请求由PHP代码完成,并使用cURL发出请求。这可以在99.9%的时间内正常运行,奇怪的是某些请求始终失败。这些请求的结构与其他请求类似,只会导致超时。
如果我通过Postman提交了相同的请求,则会得到所需的响应。物流公司建议错误在于我的实施,我愿意这样。有人可以协助吗?
$log = new Log('LOG.log');
if($quote['pargo'] == 1){
//make request to URL - need to get city and postal code from $json
$url = "[http://requestEndPoint]".$requestString;
$log->write('API Request= ' . $url);
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array(
"Content-Type:application/json",
"Authorization: [apiKey]"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$log->write('API Response= ' . json_encode($response));
if($response){
$obj = $response;
}
else{
$obj = curl_error($ch);
}
curl_close($ch);
$counter++;
}
在失败的特定呼叫上,从服务器收到的响应为:
400 Bad Request
请求的性质是以提供的格式(城市,国家/地区)获取有关给定地址的信息。工作$requestString
的示例如下:
Sandton, Johannesburg, South Africa
以下是与cURL一致失败但可以在Postman中使用的
Hermanus Heights, Hermanus, South Africa