21,886
社区成员
发帖
与我相关
我的任务
分享
$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();
$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=c415deb6fcd5ecb861ff24a0e0fc22856d2ecfd394ca9e6352d0b01160ac0ec57b9c5c10beb8cf9b0458f95b; Path=/
)
该站使用了 session 和 stoke 而你却没有
自然就模拟失败了$cookie_file = dirname(__FILE__).'/cookie.txt';
$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";
$curl = curl_init($url); //初始化
curl_setopt($curl, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储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']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//ob_start();
$output=curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
print_r($output);
[/quote]
获取到页面cookie就可[/quote]
获取到cookies了,如下:
# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
dct.dhl.com FALSE / FALSE 0 JSESSIONID G30pSQnJ1zG42JpFLY73P8p4HJKgKYvG6TpLst1tg2yrw7KyRNcR!1491498917
dct.dhl.com FALSE / FALSE 0 BIGipServerdct_ratio 594036901.42783.0000
dct.dhl.com FALSE / FALSE 0 TSe13065 71b4e5e7aaebc5bce14509eaca39a22d7832faa0207c199652d0eea960ac0ec5f65a5565beb8cf9b2a58f6f0
但还是post失败[/quote][/quote]老兄知不知道怎么解决啊?[/quote]
老兄 小弟不知$cookie_file = dirname(__FILE__).'/cookie.txt';
$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";
$curl = curl_init($url); //初始化
curl_setopt($curl, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储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']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//ob_start();
$output=curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
print_r($output);
[/quote]
获取到页面cookie就可[/quote]
获取到cookies了,如下:
# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
dct.dhl.com FALSE / FALSE 0 JSESSIONID G30pSQnJ1zG42JpFLY73P8p4HJKgKYvG6TpLst1tg2yrw7KyRNcR!1491498917
dct.dhl.com FALSE / FALSE 0 BIGipServerdct_ratio 594036901.42783.0000
dct.dhl.com FALSE / FALSE 0 TSe13065 71b4e5e7aaebc5bce14509eaca39a22d7832faa0207c199652d0eea960ac0ec5f65a5565beb8cf9b2a58f6f0
但还是post失败[/quote][/quote]老兄知不知道怎么解决啊?$cookie_file = dirname(__FILE__).'/cookie.txt';
$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";
$curl = curl_init($url); //初始化
curl_setopt($curl, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储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']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//ob_start();
$output=curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
print_r($output);
[/quote]
获取到页面cookie就可[/quote]
获取到cookies了,如下:
# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
dct.dhl.com FALSE / FALSE 0 JSESSIONID G30pSQnJ1zG42JpFLY73P8p4HJKgKYvG6TpLst1tg2yrw7KyRNcR!1491498917
dct.dhl.com FALSE / FALSE 0 BIGipServerdct_ratio 594036901.42783.0000
dct.dhl.com FALSE / FALSE 0 TSe13065 71b4e5e7aaebc5bce14509eaca39a22d7832faa0207c199652d0eea960ac0ec5f65a5565beb8cf9b2a58f6f0
但还是post失败[/quote]$cookie_file = dirname(__FILE__).'/cookie.txt';
$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";
$curl = curl_init($url); //初始化
curl_setopt($curl, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储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']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//ob_start();
$output=curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
print_r($output);
[/quote]
获取到页面cookie就可[/quote]
获取到cookies了,如下:
# Netscape HTTP Cookie File
# http://curlm.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
dct.dhl.com FALSE / FALSE 0 JSESSIONID G30pSQnJ1zG42JpFLY73P8p4HJKgKYvG6TpLst1tg2yrw7KyRNcR!1491498917
dct.dhl.com FALSE / FALSE 0 BIGipServerdct_ratio 594036901.42783.0000
dct.dhl.com FALSE / FALSE 0 TSe13065 71b4e5e7aaebc5bce14509eaca39a22d7832faa0207c199652d0eea960ac0ec5f65a5565beb8cf9b2a58f6f0
但还是post失败$cookie_file = dirname(__FILE__).'/cookie.txt';
$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";
$curl = curl_init($url); //初始化
curl_setopt($curl, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储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']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//ob_start();
$output=curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
print_r($output);
[/quote]
获取到页面cookie就可$cookie_file = dirname(__FILE__).'/cookie.txt';
$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";
$curl = curl_init($url); //初始化
curl_setopt($curl, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //存储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']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($ch, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//ob_start();
$output=curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
print_r($output);