dongxian7489 2016-01-26 15:00
浏览 52

用cURL填写外部表格

I'm trying to fill and submit an external form using cURL, but actually I can't fill the field and I would understand why.

How can I see the filled form, immediately after the form submission?

I have the following code:

    <?php

         //create array of data to be posted
           $post_data['fname'] = 'Mario';
           $post_data['lname'] = 'Rossi';
           $post_data['email'] = 'mario@rossi.it';
           $post_data['memberid'] = '1010101010';
           $post_data['mobile'] = '3456789';


         //traverse array and prepare data for posting (key1=value1)

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

           //create the final string to be posted using implode()

           $post_string = implode ('&', $post_items);

           //create cURL connection
           $curl_connection = 
                   curl_init('http://dennehys.ie/mobile/douglas/formview.php?qstr=dHlwbz0mZGF5PVR1ZXNkYXkmZGF5ZGF0ZT0yMDE2LTAxLTI2JnJuZD0mY2xhc3NzaGVkdWxlPTQ5Mw==');

          //set options
          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);

          //set data to be posted
          curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

          //perform our request
          $result = curl_exec($curl_connection);
          print_r($post_data);
          echo $result;

          //show information regarding the request

          print_r(curl_getinfo($curl_connection));
          echo curl_errno($curl_connection) . '-' . 
            curl_error($curl_connection);

         //close the connection
          curl_close($curl_connection);

     ?>
  • 写回答

2条回答 默认 最新

  • duanchongchu5177 2016-01-26 15:03
    关注

    Looking at the page you are posting to, the form has the following line:

    <form action="formresponse.php" method="post" data-ajax="false" name="book">
    

    This implies that you are posting data to the wrong page, as all the posted data from that form goes to formresponse.php. It's likely that the page you're sending to doesn't do anything with the data you're posting.

    Try changing this line:

    curl_init('http://dennehys.ie/mobile/douglas/formview.php?qstr=dHlwbz0mZGF5PVR1ZXNkYXkmZGF5ZGF0ZT0yMDE2LTAxLTI2JnJuZD0mY2xhc3NzaGVkdWxlPTQ5Mw==');
    

    to:

    curl_init('http://dennehys.ie/mobile/douglas/formresponse.php');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?