CURL Problem.. Comparing output from IE/CURL differs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wescotte

    CURL Problem.. Comparing output from IE/CURL differs

    I'm writing a tiny php app that will log into our bank of america
    account and retrieve a file containing a list of checks that cleared
    the previous day. The problem I'm running into is when I perform
    actions with php/CURL the output is different than when I use IE and
    I'm completely stumped as to why. The final output should list files
    available for retrieval but the CURL output displays an error/empty
    file message.

    Here is the curl portion of my code

    global $ERROR_MESSAGE;

    $ch = curl_init();
    $POSTFIELDS =
    "remote=MYLOGIN &password=MYPAS SWORD&Submit=Su bmit&operation= LOGON";

    curl_setopt($ch , CURLOPT_RETURNT RANSFER, TRUE);
    curl_setopt($ch , CURLOPT_URL,
    "https://elink-http4.bankofame rica.com/servlet/MailboxServlet" );
    curl_setopt($ch , CURLOPT_SSL_VER IFYPEER, FALSE);
    curl_setopt($ch , CURLOPT_USERAGE NT, "Mozilla/4.0 (compatible; MSIE
    5.01; Windows NT 5.0)");
    curl_setopt($ch , CURLOPT_POST, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, "$POSTFIELD S");
    curl_setopt($ch , CURLOPT_COOKIEJ AR, "/ReconsileCookie ");

    $stuff=curl_exe c($ch);
    curl_close($ch) ;

    echo $stuff;
    $pos = strrpos($stuff, "Logon is successful.");
    if ($pos === false)
    $ERROR_MESSAGE = "\tUnable to login.\n";

    if (curl_errno($ch ))
    $ERROR_MESSAGE = "\t" . curl_error($ch) . "\n";


    if ($ERROR_MESSAGE == "") { // Login succesfull... Continue retrieval
    of file
    $ch = curl_init();

    $formvars = array();
    $formvars["Submit"]="Submit";
    $formvars["operation"]="DIRECTORY" ;

    curl_setopt($ch , CURLOPT_RETURNT RANSFER, TRUE);
    curl_setopt($ch , CURLOPT_URL,
    "https://elink-http4.bankofame rica.com/servlet/MailboxServlet" );
    curl_setopt($ch , CURLOPT_SSL_VER IFYPEER, FALSE);
    curl_setopt($ch , CURLOPT_USERAGE NT, "Mozilla/4.0 (compatible; MSIE
    5.01; Windows NT 5.0)");
    curl_setopt($ch , CURLOPT_POST, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, $formvars);
    curl_setopt($ch , CURLOPT_COOKIEF ILE, "/ReconsileCookie ");

    $stuff=curl_exe c($ch);
    curl_close($ch) ;
    echo $stuff;

    $pos = strrpos($stuff, "Send is successful.");
    if ($pos === false)
    $ERROR_MESSAGE ="\tFailed to send edi.txt to bank.\n";


    if (curl_errno($ch ))
    $ERROR_MESSAGE = "\t" . curl_error($ch) . "\n";

    }

    Below is the output I get when I execute the above portion of code

    <html>
    <body>

    <HTML>
    <HEAD><LINK rel="stylesheet " type="text/css" name="defaultst yle"
    href="/cehttp/html/style.css">
    <TITLE>Servle t Response Message</TITLE></HEAD>
    <BODY>
    <H2 align=center>Se rvlet has returned the following message</H2>
    <HR>
    Logon is successful.
    <HR>
    </BODY></HTML>
    <HTML>
    <HEAD><LINK rel="stylesheet " type="text/css" name="defaultst yle"
    href="/cehttp/html/style.css">
    <TITLE>Servle t Response Message</TITLE></HEAD>
    <BODY>
    <H2 align=center>Se rvlet has returned the following message</H2>
    <HR>
    The file is empty or does not exist. Return Code: 701
    <HR>
    </BODY></HTML>

    </body>
    </html>


    Now, if I use IE to login to the website I recieve

    <HTML>
    <HEAD><LINK rel="stylesheet " type="text/css" name="defaultst yle"
    href="/cehttp/html/style.css">
    <TITLE>Servle t Response Message</TITLE></HEAD>
    <BODY>
    <H2 align=center>Se rvlet has returned the following message</H2>
    <HR>
    Logon is successful.
    <HR>
    </BODY></HTML>



    After I login I continue with the button to display my file directory
    contents and the output is as follows


    <HTML><HEAD><LI NK rel="stylesheet " type="text/css" name="defaultst yle"
    href="/cehttp/html/style.css">
    <TITLE>CONNECT: Enterprise -Directory</TITLE></HEAD>
    <BODY>
    <CENTER><TABL E BORDER=1>
    <CAPTION>CONNEC T:Enterprise Directory Contents</CAPTION>
    <TR>
    <TH>Mailbox</TH>
    <TH>Batch#</TH>
    <TH>Size</TH>
    <TH>Descripti on (Batch ID)</TH>
    <TH>Creation Date</TH>
    <TH>Creation Time</TH>
    <TH>Flags</TH>
    </Table></CENTER>
    <CENTER>Numbe r of batches: 0</CENTER>
    </BODY></HTML>



    Here is the HTML source for the login page.


    <HTML>
    <HEAD>
    <LINK rel="stylesheet " type="text/css"
    name="defaultst yle" href="style.css "><TITLE>CONNEC T:Enterprise -
    Logon</TITLE>
    </HEAD>
    <BODY >


    <H2>Logon Option</H2>

    <FORM METHOD="POST" ACTION="/servlet/MailboxServlet" >

    <P><table border=1 cellpadding=4 cellspacing=4
    summary="Instru ction box"><tr><td bgcolor="#CC000 0"><font
    color="#FFFFFF" ><b>To log on, fill in the necessary fields below and
    click on the Submit button.</b></font>
    </td></tr>
    </table></P>

    <table border=0 cellpadding=0 cellspacing=0>
    <tr><td>User ID: </td><td><INPUT TYPE="TEXT"
    NAME="remote" SIZE="9" MAXLENGTH="64"> </td></tr>
    <tr><td>Passwor d:</td><td><INPUT
    TYPE="PASSWORD" NAME="password" SIZE="9" MAXLENGTH="16"> </td></tr>

    </table>

    <P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit"
    CHECKED="CHECKE D">
    <INPUT TYPE="RESET" NAME="Cancel" VALUE="Reset"></P>
    <INPUT TYPE="HIDDEN" NAME="operation " VALUE="LOGON">

    </FORM>
    </BODY>
    </HTML>

    And here is the source for the 2nd Post data page

    <HTML>

    <HEAD>
    <LINK rel="stylesheet " type="text/css" href="style.css ">
    <TITLE>CONNECT: Enterprise - Directory</TITLE>

    </HEAD>

    <BODY>
    <FORM METHOD="POST" ACTION="/servlet/MailboxServlet" >

    <H2>Directory Option</h2>

    <table border=1 cellpadding=4 cellspacing=4 summary="Instru ction
    box"><tr><td bgcolor="CC0000 "><font color="#FFFFFF" ><strong>To see and
    download available files, click on the Submit
    button.</strong></font></td></tr>
    </table>
    <br>

    <P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit" CHECKED="CHECKE D">
    <INPUT TYPE="HIDDEN" NAME="operation " VALUE="DIRECTOR Y"></P><br>


    </FORM>
    </BODY>
    </HTML>

    Any ideas as to why CURL produces different results? Also I've already
    used a CURL based app using almost the identical code above to login
    and send a checks cut today file which correctly works..


    Thanks
    Eric Wescott

  • Andy Hassall

    #2
    Re: CURL Problem.. Comparing output from IE/CURL differs

    On 7 Nov 2005 13:51:53 -0800, "Wescotte" <wescotte@earth link.net> wrote:
    [color=blue]
    >curl_setopt($c h, CURLOPT_COOKIEJ AR, "/ReconsileCookie ");[/color]

    From a brief glance this is the only bit that looked slightly odd - is this a
    valid, writable file for the cookie jar?
    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Wescotte

      #3
      Re: CURL Problem.. Comparing output from IE/CURL differs

      Yes, the cookie itself is correctly created and correctly loaded.
      Originally I set it to just "cookie" but I wanted to keep it seperate
      so I changed the name to a more recognizable one.

      Comment

      • Wescotte

        #4
        Re: CURL Problem.. Comparing output from IE/CURL differs

        I found the issue..
        If I use
        curl_setopt($ch , CURLOPT_POSTFIE LDS,
        "operation=DIRE CTORY&Submit=Su bmit");

        it works
        but with

        $formvars = array();
        $formvars["Submit"]="Submit";
        $formvars["operation"]="DIRECTORY" ;
        curl_setopt($ch , CURLOPT_POSTFIE LDS, $formsvars);

        it does not..
        Any idea why?

        Comment

        • Andy Hassall

          #5
          Re: CURL Problem.. Comparing output from IE/CURL differs

          On 9 Nov 2005 08:55:31 -0800, "Wescotte" <wescotte@earth link.net> wrote:
          [color=blue]
          >I found the issue..
          >If I use
          >curl_setopt($c h, CURLOPT_POSTFIE LDS,
          >"operation=DIR ECTORY&Submit=S ubmit");
          >
          >it works
          >but with
          >
          >$formvars = array();
          >$formvars["Submit"]="Submit";
          >$formvars["operation"]="DIRECTORY" ;
          >curl_setopt($c h, CURLOPT_POSTFIE LDS, $formsvars);
          >
          >it does not..
          >Any idea why?[/color]

          Maybe:



          Particularly look at revisions 1.30 and 1.46 and the bug it references?

          It's not exactly well documented when you're supposed to pass as the parameter
          when using CURLOPT_POSTFIE LDS.

          ' CURLOPT_POSTFIE LDS The full data to post in a HTTP "POST" operation.'

          This seems to mean the raw POST data as per your first bit of code, but some
          versions of the PHP curl extension seem to accept arrays (which is useful).
          Looking at the code it appears to accept objects too.
          --
          Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
          http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

          Comment

          • Wescotte

            #6
            Re: CURL Problem.. Comparing output from IE/CURL differs

            Well, the strange thing is I've used an array before for passing post
            data and it worked correctly.

            Comment

            • Manuel Lemos

              #7
              Re: CURL Problem.. Comparing output from IE/CURL differs

              Hello,

              on 11/07/2005 07:51 PM Wescotte said the following:[color=blue]
              > Any ideas as to why CURL produces different results? Also I've already
              > used a CURL based app using almost the identical code above to login
              > and send a checks cut today file which correctly works..[/color]

              I have seen this behaviour with some version of Curl that do not handle
              HTTP 1.1 responses with code 100. This is not an error but CUrl could
              not handle it properly.

              Personally I use this HTTP client class that uses fsockopen with OpenSSL
              when available. Otherwise, internally it falls back to curl but changes
              the request a bit to avoid the bug. You may want to try the class to see
              if it solves your problem too:




              --

              Regards,
              Manuel Lemos

              Metastorage - Data object relational mapping layer generator


              PHP Classes - Free ready to use OOP components written in PHP
              Free PHP Classes and Objects 2026 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials

              Comment

              Working...