#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Post to external site with curl


    Hi, i am trying to post something to external site, and i found out best way to do this is cURL.

    Here is my code:
    PHP Code:
    <html>
    <body>
    <?php
    include('simple_html_dom.php');
    $url "example.com";
    $a "744bhz";
    $html = new simple_html_dom();
    $ch curl_init();
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_FAILONERROR1);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT30);
    curl_setopt($chCURLOPT_USERAGENT,
            
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_POSTFIELDS'pregnr=' urlencode($a));
    $result curl_exec($ch);
    echo 
    $result;
    curl_close($ch);
    ?>
    </body>
    </html>
    Problem is it only loads me blank page nothing else, i have error reporting enabled in php.ini, but no errors, just blank page.

    Site html is like this:
    Code:
    <FORM NAME="kindlustuskate" METHOD="POST" ACTION="SYSADM.LK_INFOKESKUS_PKT.kindlustuskate">
    <input type="hidden" name="plang" value="ENG">
    <TABLE width=100%  CELLPADDING=3 CELLSPACING=0 BORDER=0>
    <tr>
                   <td align="right" width=350>Registration plate number</td>
                   <td  width=10>&nbsp;</td>
                   <td><input type="text" name="pregnr" value=""> <font size="1">For example 000XXX</font></td>
                </tr>
    <tr>
                   <td align="right" width=350>Vehicle VIN code</td>
                   <td  width=10>&nbsp;</td>
                   <td><input type=text name=pvin value=> <font size=1>For example 45XXXXXXXXXXXXXXXXX65</font></td>
                </tr>
    <tr>
                   <td align="right" width=350>Insurance policy number</td>
                   <td  width=10>&nbsp;</td>
                   <td><input type=text name=ppolnr value=""> <font size=1>For Example E0000000T</font></td>
                </tr>
    <tr>
                   <td align="right" width=350>Date of validity</td>
                   <td  width=10>&nbsp;</td>
                   <td><input type=text name=pkuup value="">&nbsp;<font size=1>dd.mm.yyyy</font></td>
                </tr>
    <tr>
    <td align=right valign=top>Area of validity</td>
    <td align=right valign=top>&nbsp;</td>
    <td align=left valign=middle>
    <input type=radio name="pala" checked value="1">European Economic Area (EEA) member state or Switzerland<br>
    <input type="radio" name="pala" value="2">Green card system country<br>
    </td></tr>
    <tr>
                   <td align="right" width=350>&nbsp;</td>
                   <td  width=10>&nbsp;</td>
                   <td><input type="submit" name="potsi" value="Find"></td>
                </tr>
    </table>
    </form>

    Site is https, i dont know if this matters or not, but ihave set sssl verify false in curl anyway.
    I have messed with this for many hours, any ideas?
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    Why do people just automatically assume every call they makes succeeds without checking?

    php Code:
     
    $result = curl_exec($ch);
    if ($result === FALSE)
    {
        echo ("ERROR: " . curl_error($ch));
    }
    curl_close($ch);


    If the error you're getting is

    Code:
    ERROR: error:14077417:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert illegal parameter
    then add

    php Code:
    curl_setopt($ch, CURLOPT_SSLVERSION, 3);
    Last edited by ptr2void; January 28th, 2013 at 05:35 PM.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    And you'll have to pass more than just the license plate number otherwise the form just redisplays itself.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    And you'll have to pass more than just the license plate number otherwise the form just redisplays itself.
    But in original site i can just input license plate and click submit, why cant i do this with curl?

    vs.lkf.ee/pls/xlk/SYSADM.LK_INFOKESKUS_PKT.kindlustuskate

    Just add https in front of it, i cant post live links here.

    For example 217thd.
  8. #5
  9. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    Because not entering values is not the same as not passing them along at all.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    this matters or not


    i dont know if this matters or not, but ihave set sssl verify false in curl anyway.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    Because not entering values is not the same as not passing them along at all.
    But how can i pass empty value with curl, i tried "0" but that wont work. It fills form with 0.

    Maybe
    PHP Code:
    curl_setopt($chCURLOPT_POSTFIELDS'formname='); 
    ??
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    I tried with
    Code:
     curl_setopt($ch, CURLOPT_POSTFIELDS, 'formname=');
    Nothing, it just loads the site as anything is not submited, anyone have any ideas?

    PHP Code:
    <html>
    <body>
    <?php
    include('simple_html_dom.php');
    $url "https://vs.lkf.ee/pls/xlk/SYSADM.LK_INFOKESKUS_PKT.kindlustuskate?plang=EST";
    $a "744bhz";
    $html = new simple_html_dom();
    $ch curl_init();
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_FAILONERROR1);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT30);
    curl_setopt($chCURLOPT_USERAGENT,
            
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
    curl_setopt($chCURLOPT_SSLVERSION3);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_POSTFIELDS'pregnr=' urlencode($a));
    curl_setopt($chCURLOPT_POSTFIELDS'pvin=');
    curl_setopt($chCURLOPT_POSTFIELDS'ppolnr=');
    curl_setopt($chCURLOPT_POSTFIELDS'pkuup=');
    $result curl_exec($ch);
    if (
    $result === FALSE)
    {
        echo (
    "ERROR: " curl_error($ch));
    }

    curl_close($ch);
    echo 
    $result;
    ?>
    </body>
    </html>
  16. #9
  17. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    All those curl_setopt()s you have are overwriting each other.

    Give it an array of the values you want to send.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by requinix
    All those curl_setopt()s you have are overwriting each other

    Give it an array of the values you want to send.
    Thanks for the hint, i made an array with values, but i am still not sure if passing empty data is done right, anyway still no success, script still loads site as no data has been entered.

    Code with changes:
    PHP Code:
    <html>
    <body>
    <?php
    include('simple_html_dom.php');
    $url "https://vs.lkf.ee/pls/xlk/SYSADM.LK_INFOKESKUS_PKT.kindlustuskate?plang=EST";

    $data = array('pregnr' => '217thd''pvin' => '''ppolnr' => '''pkuup' => '' );


    $html = new simple_html_dom();
    $ch curl_init();
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_FAILONERROR1);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT30);
    curl_setopt($chCURLOPT_USERAGENT,
            
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
    curl_setopt($chCURLOPT_SSLVERSION3);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_POST1);

    curl_setopt($chCURLOPT_POSTFIELDS,  $data);


    $result curl_exec($ch);
    if (
    $result === FALSE)
    {
        echo (
    "ERROR: " curl_error($ch));
    }
    curl_close($ch);
    echo 
    $result;
    ?>
    </body>
    </html>
    I appreaciate any help , since i am newbie in php
  20. #11
  21. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,070
    Rep Power
    9398
    That's right, but you still haven't included all the form fields.

    Example: when you click a named submit button, its name and value are included in the request.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    10
    Rep Power
    0

    Thumbs up


    [QUOTE=requinix]That's right, but you still haven't included all the form fields.

    Example: when you click a named submit button, its name and value are included in the request.[/QUOTE

    Ha, i see, thank you very much !!!

    Got it working
    PHP Code:
    $data = array('plang' => 'EST','pregnr' => '217thd''pvin' => '''ppolnr' => '''pkuup' => '''pala' => '1''potsi' => 'Otsi' ); 
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0
    Thank You mate sincerely so much for this topic!
    Was just working with the same god damn insurance data reading issue and struggling with similar error, but You made my life so much easier

    Tauno

    [QUOTE=MikkM]
    Originally Posted by requinix
    That's right, but you still haven't included all the form fields.

    Example: when you click a named submit button, its name and value are included in the request.[/QUOTE

    Ha, i see, thank you very much !!!

    Got it working
    PHP Code:
    $data = array('plang' => 'EST','pregnr' => '217thd''pvin' => '''ppolnr' => '''pkuup' => '''pala' => '1''potsi' => 'Otsi' ); 

IMN logo majestic logo threadwatch logo seochat tools logo