PHP Curl POST Request to iFrame



我需要在这个跟踪网站中跟踪一个跟踪号。但是,表单在iFramediv中,如何在PHP中使用CURL发布请求?下面是我的代码。

iFrame src:

https://home.abxexpress.com.my/track_multiple.html

原始来源:

https://abxexpress.com.my/Home/Tracking

控制器:

public function track($trackingID)
{
$data = array(
'tairbillno'  => $trackingID
);
print_r($data);
$url = file_get_contents('https://home.abxexpress.com.my/track_multiple.html');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($curl);
curl_close($curl);
echo $result;
}

追踪号码样本:

99951513362

您可以使用此php-curl代码向回调页面发送一个简单的post请求,以获取html格式的跟踪信息, 在您可以直接在您的网站中打印内容(它工作正确,具有原始样式(之后,您也可以使用此内容来提取您想要的所有信息,通过任何 DOM 提取库,例如:php DOMDocument

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://home.abxexpress.com.my/track_multipleResult.asp?vsearch=True');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "tairbillno=99951513362");//replace number your traking number 
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Connection: keep-alive';
$headers[] = 'Pragma: no-cache';
$headers[] = 'Cache-Control: no-cache';
$headers[] = 'Upgrade-Insecure-Requests: 1';
$headers[] = 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36';
$headers[] = 'Origin: https://home.abxexpress.com.my';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
$headers[] = 'Sec-Fetch-Site: same-origin';
$headers[] = 'Sec-Fetch-Mode: navigate';
$headers[] = 'Sec-Fetch-User: ?1';
$headers[] = 'Sec-Fetch-Dest: document';
$headers[] = 'Referer: https://home.abxexpress.com.my/track_multiple.html';
$headers[] = 'Accept-Language: it,it-IT;q=0.9,en-US;q=0.8,en;q=0.7,ar;q=0.6';
$headers[] = 'Cookie: ASPSESSIONIDAWDDSADQ=LLOJGMICLOOKHGEHJHPBMBKE';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

相关内容

  • 没有找到相关文章

最新更新