curl post错误,求解

theFucM 2014-01-10 11:52:58
$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();

不知道为什么post不成功啊,求救
...全文
300 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2014-01-11
  • 打赏
  • 举报
回复
$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 而你却没有 自然就模拟失败了
theFucM 2014-01-11
  • 打赏
  • 举报
回复
引用 3 楼 zy205817 的回复:
// 检查是否有错误发生 if(curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); }
没错误。数据能post,就是不清楚为什么不能成功post?求救啊
theFucM 2014-01-11
  • 打赏
  • 举报
回复
引用 2 楼 microlab2009 的回复:
哦 看错了 你想要的是把数字填充到表单里是吧 curl只能模拟表单提交的
可能我没说清楚,我需要的是post成功后的结果,可这个页面不是post成功后的页面
theFucM 2014-01-11
  • 打赏
  • 举报
回复
引用 楼主 u013442052 的回复:
$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();

不知道为什么post不成功啊,求救

POST 成功后的页面多了个result,运行后打印出来的页面没有啊
码无边 2014-01-11
  • 打赏
  • 举报
回复
// 检查是否有错误发生 if(curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); }
嘻哈大咖秀 2014-01-11
  • 打赏
  • 举报
回复
哦 看错了 你想要的是把数字填充到表单里是吧 curl只能模拟表单提交的
嘻哈大咖秀 2014-01-11
  • 打赏
  • 举报
回复

我这边是正确的啊
你看下你的curl环境是否正确
xuzuning 2014-01-11
  • 打赏
  • 举报
回复
一般宜先获取 cookie 后再模拟提交 他的表单是 js 生成的,你都分析过了吗? 你提交的参数远比表单显示的少
legendnan 2014-01-11
  • 打赏
  • 举报
回复
引用 12 楼 u013442052 的回复:
[quote=引用 11 楼 legendnan 的回复:] [quote=引用 10 楼 u013442052 的回复:] [quote=引用 9 楼 zy205817 的回复:] [quote=引用 8 楼 u013442052 的回复:] [quote=引用 7 楼 xuzuning 的回复:]
$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 而你却没有 自然就模拟失败了
加上了cookies,不知怎么加session,大牛帮我看看啊,谢谢
$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] 老兄 小弟不知
theFucM 2014-01-11
  • 打赏
  • 举报
回复
引用 11 楼 legendnan 的回复:
[quote=引用 10 楼 u013442052 的回复:] [quote=引用 9 楼 zy205817 的回复:] [quote=引用 8 楼 u013442052 的回复:] [quote=引用 7 楼 xuzuning 的回复:]
$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 而你却没有 自然就模拟失败了
加上了cookies,不知怎么加session,大牛帮我看看啊,谢谢
$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]老兄知不知道怎么解决啊?
legendnan 2014-01-11
  • 打赏
  • 举报
回复
引用 10 楼 u013442052 的回复:
[quote=引用 9 楼 zy205817 的回复:] [quote=引用 8 楼 u013442052 的回复:] [quote=引用 7 楼 xuzuning 的回复:]
$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 而你却没有 自然就模拟失败了
加上了cookies,不知怎么加session,大牛帮我看看啊,谢谢
$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]
theFucM 2014-01-11
  • 打赏
  • 举报
回复
引用 9 楼 zy205817 的回复:
[quote=引用 8 楼 u013442052 的回复:] [quote=引用 7 楼 xuzuning 的回复:]
$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 而你却没有 自然就模拟失败了
加上了cookies,不知怎么加session,大牛帮我看看啊,谢谢
$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失败
码无边 2014-01-11
  • 打赏
  • 举报
回复
引用 8 楼 u013442052 的回复:
[quote=引用 7 楼 xuzuning 的回复:]
$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 而你却没有 自然就模拟失败了
加上了cookies,不知怎么加session,大牛帮我看看啊,谢谢
$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就可
theFucM 2014-01-11
  • 打赏
  • 举报
回复
引用 7 楼 xuzuning 的回复:
$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 而你却没有 自然就模拟失败了
加上了cookies,不知怎么加session,大牛帮我看看啊,谢谢
$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);

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧