Phone: 15534080002 Email: mail.min@163.com

php curl多次请求返回慢与curl自身域名DNS转换有关,修改成IP请求后正常

2021-12-06 09:46:59 8306 山西更新科技

请求域名对应host添加到请求头中

<?php

$host = gethostbyname('kingcard.dgunicom.com');

curl_setopt($ch, CRULOPT_HTTPHEADER, ['Host: '.$host]);

?>

$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, 'https://kingcard.dgunicom.com/dgZop/api/numSelect');
curl_setopt($ch, CURLOPT_URL, 'https://211.95.193.53/dgZop/api/numSelect');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

$headers = array();
$headers[] = 'Host: kingcard.dgunicom.com';
$headers[] = 'Content-Type: application/json';
$headers[] = 'Expect:';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;

ligengxin.com@2022 Powered by SIYUCMS
备案号:晋ICP备2021016272号