curl发布一个远程表单,并在var中得到结果

时间:2013-02-07 09:16:43

标签: php curl

以下代码是发布远程表单。

<?php
$post_data['mail'] = 'parcel';
$post_data['destination'] = '1';
$post_data['weight'] = '300';


foreach ( $post_data as $key => $value) 
{
    $post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);


$curl_connection = curl_init('http://app1.hongkongpost.com/calc/eng/overseas/step2.php');

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

$result = curl_exec($curl_connection);
//curl_close($curl_connection);
var_dump($reuslt);

print_r(curl_getinfo($curl_connection));

?>

结果是NULL,但是如果我评论该行 curl_setopt($ curl_connection,CURLOPT_RETURNTRANSFER,true);

页面返回将返回 http://app1.hongkongpost.com/calc/eng/overseas/step2.php 并显示结果(这意味着帖子成功),但我只想获得该表,而不是返回结果页面。有谁知道这是什么问题?

1 个答案:

答案 0 :(得分:1)

  1. 不正确的变量名$ reuslt。替换:“var_dump($ reuslt);” “var_dump($ result);”
  2. 添加curl_setopt($ curl_connection,CURLOPT_POST,1);