【问题标题】:Fill external form with cURL用 cURL 填写外部表单
【发布时间】:2016-05-03 04:44:19
【问题描述】:

我正在尝试使用 cURL 填写和提交外部表单,但实际上我无法填写该字段,我会理解原因。

如何在表单提交后立即查看已填写的表单?

我有以下代码:

    <?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);

     ?>

【问题讨论】:

    标签: php forms post curl


    【解决方案1】:

    查看您要发布到的页面,表单有以下行:

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

    这意味着您将数据发布到错误页面,因为该表单中的所有发布数据都发送到formresponse.php。您发送到的页面很可能对您发布的数据没有任何作用。

    尝试更改此行:

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

    到:

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

    【讨论】:

    【解决方案2】:

    我更改了行并修复了我的代码,因为有四种隐藏的输入类型,现在代码看起来可以正常工作,但我不确定。

    隐藏的输入类型是:

    'typo' 一个空字段(我认为该字段是空的)

    'day' = '星期三'; (你想预订课程的那一天)

    'clsdl' = '485'; (类 ID)

    'daydate' = '2016-01-27'; (上课日期)

    当我发送请求时,代码会回复我一条成功消息。

    现在我不明白如何在特定时间发送预订课程的请求。

    我的意思是,有可能在同一天有两个相同运动的课程,我想指定我想要预订的课程。

    我试图阅读页面的源代码,但我不明白我该怎么做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多