Curlpost error. solve $ urldct. dhl. cominput. jsp? Lang; $ post_dataorgCtryCHINA, & nbsp; PEOPLES & nbsp; REPUBLIC & nbsp; (CN) & amp; orgZip510011 & amp; orgCityGUANGZ curl post error, solve
$url="http://dct.dhl.com/input.jsp?langId=cn&originCCId=CN";
$post_data="orgCtry=CHINA, PEOPLES REPUBLIC (CN)&orgZip=510011&orgCity=GUANGZHOU&dstCtry=HONG KONG (HK)&dstCity=HONG KONG&declValCur=USD&weight=0.2&shipping_options=Submit";
$ch=curl_init();
echo phpinfo();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
//ob_start();
$output=curl_exec($ch);
curl_close($ch);
print_r($output);
//ob_end_flush();
I don't know why the post fails. ask for help.
Share: More
------ Solution --------------------
// Check for any errors
If (curl_errno ($ ch ))
{
Echo 'curl error: '. curl_error ($ ch );
}
------ Solution --------------------
$url="http://dct.dhl.com/input.jsp?langId=cn&originCCId=CN";
print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 11 Jan 2014 02:44:34 GMT
[2] => Content-Length: 10641
[3] => Content-Type: text/html; charset = UTF-8
[4] => X-Powered-By: Servlet/2.5 JSP/2.1
[5] => Set-Cookie: JSESSIONID = pmT2SQwS3QSTgbTCNygyJlPjvC3hKmkgHDyJYQys145vGnvmBpbP! 1824887213; path =/; HttpOnly
[6] => Set-Cookie: BIGipServerdct_ratio = 627591333.43295.0000; path =/
[7] => Via: 1.0 dct.dhl.com
[8] => Connection: close
[9] => Set-Cookie: TSe13065 = secure; Path =/
)
This site uses session and stoke, but you do not
Naturally, the simulation fails.
------ Solution --------------------
Reference:
Quote: reference:
$url="http://dct.dhl.com/input.jsp?langId=cn&originCCId=CN";
print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Date: Sat, 11 Jan 2014 02:44:34 GMT
[2] => Content-Length: 10641
[3] => Content-Type: text/html; charset = UTF-8
[4] => X-Powered-By: Servlet/2.5 JSP/2.1
[5] => Set-Cookie: JSESSIONID = pmT2SQwS3QSTgbTCNygyJlPjvC3hKmkgHDyJYQys145vGnvmBpbP! 1824887213; path =/; HttpOnly
[6] => Set-Cookie: BIGipServerdct_ratio = 627591333.43295.0000; path =/
[7] => Via: 1.0 dct.dhl.com
[8] => Connection: close
[9] => Set-Cookie: TSe13065 = secure; Path =/
)
This site uses session and stoke, but you do not
Naturally, the simulation fails.
I don't know how to add session with cookies. Daniel can help me check it out. thank you.
$ Cookie_file = dirname (_ FILE _). '/cookie.txt ';
$ Url = "http://dct.dhl.com/input.jsp? LangId = cn & originCCId = CN ";
$ Post_data = "orgCtry = CHINA, les REPUBLIC (CN) & orgZip = 510011 & orgCity = GUANGZHOU & dstCtry = hong kong (HK) & dstCity = hong kong & declValCur = USD & weight = 0.2 & shipping_options = Submit ";
$ Curl = curl_init ($ url); // Initialization
Curl_setopt ($ curl, CURLOPT_HEADER, 0); // the header section is not returned.
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true); // returns a string instead of a direct output.
Curl_setopt ($ curl, CURLOPT_COOKIEJAR, $ cookie_file); // store cookies
Curl_exec ($ curl );
Curl_close ($ curl );
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_USERAGENT, $ _ SERVER ['http _ USER_AGENT ']);