I want to use curl to simulate and query data on other websites, for example, track. thailandpost. co. thtrackinternetDefault. aspx? The record on langen is my code Ref phpcurl
I want to use curl to simulate data query on other websites
For example, check the http://track.thailandpost.co.th/trackinternet/Default.aspx? Lang = en
Record on
Below is my code
/* Test ticket No.
RA686607335CN
RA686608185CN
*/
$ Num = "RA686603157CN ";
$ Post_url = 'http: // track. thailandpost. co. th/trackinternet/Default. aspx? Lang = EN ';
$ Ch = curl_init ($ post_url );
$ Header = array (
"Host: track. thailandpost. co. th ",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; rv: 23.0) Gecko/20100101 Firefox/23.0 ",
"Connection: keep-alive ",
"Content-Type: text/html; charset = windows-874 ",
"Referer: http://track.thailandpost.co.th/trackinternet/Default.aspx ",
"Location:/trackinternet/Result. aspx ",
);
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ Con1 = curl_exec ($ ch );
Curl_close ($ ch );
// Parameters changed during post submission. the parameters are matched first and then submitted as parameters.
$ Parg = '#Preg_match_all ($ parg, $ con1, $ arg );
$ Arg [1] [0] = urlencode ($ arg [1] [0]);
$ Arg [2] [0] = urlencode ($ arg [2] [0]);
// Configure //-----------------------------------------------------------------------------------------------
$ Post_data = "Login. x = 44 & Login. y = 11 & TextBarcode = ". $ num. "& __ EVENTTARGET = Login & __ EVENTVALIDATION = ". $ arg [2] [0]. "& __ VIEWSTATE = ". $ arg [1] [0];
$ Ch = curl_init ($ post_url );
// Request header information when post is submitted
$ P_header = array (
"Accept: text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8 ",
"Accept-Encoding: gzip, deflate ",
"Accept-Language: zh-cn, zh; q = 0.8, en-us; q = 0.5, en; q = 0.3 ",
"Connection: keep-alive ",
"Host: track. thailandpost. co. th ",
"Referer: http://track.thailandpost.co.th/trackinternet/Default.aspx? Lang = en ",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; rv: 23.0) Gecko/20100101 Firefox/23.0 ",
);
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ p_header );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data );
$ Cookie_file = tempnam ('C:/', 'tg _');
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file );
$ Con = curl_exec ($ ch );
Curl_close ($ ch );
// Get the cookie and carry it to access the next page
$ Url = "http://track.thailandpost.co.th/trackinternet/Result.aspx ";
$ Ch = curl_init ($ url );
$ C_header = array (
"GET/trackinternet/Result. aspx HTTP/1.1 ",
"Host: track. thailandpost. co. th ",
"User-Agent: Mozilla/5.0 (Windows NT 6.1; rv: 23.0) Gecko/20100101 Firefox/23.0 ",
"Accept: text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8 ",
"Accept-Language: zh-cn, zh; q = 0.8, en-us; q = 0.5, en; q = 0.3 ",
"Accept-Encoding: gzip, deflate ",
"Referer: http://track.thailandpost.co.th/trackinternet/Default.aspx ",
"Connection: keep-alive ",
);
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ c_header );
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); // use automatic redirect
$ Con = curl_exec ($ ch );
Curl_close ($ ch );
Echo $ con;
The cookie file is successful, but why does it seem that the cookie does not work when accessing other pages with the cookie?