HttpWebRequest: Cookies question

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

    #1

    HttpWebRequest: Cookies question

    When I run the code below, the web server tells me that I need to
    enable cookies. Can anyone tell me what might be causing that? I'm
    trying to POST userid and password to their login web page. Thanks!

    Dim CookieJar As CookieContainer = New CookieContainer ()
    Dim WebReq As HttpWebRequest
    Dim WebResp As HttpWebResponse
    Dim StrmRdr As StreamReader
    Dim StrmWrtr As StreamWriter
    Dim PostParms As String
    Dim URLString As String
    Dim HTML as String
    = "https://www.nordstromba nking.com/onlineserv/HB/Login.cgi"

    WebReq = CType(WebReques t.Create(New Uri(URLString)) ,
    HttpWebRequest)
    WebReq.CookieCo ntainer = CookieJar
    WebReq.Credenti als = CredentialCache .DefaultCredent ials
    WebReq.UserAgen t = "Mozilla/4.0 (compatible; MSIE 6.0; Windows
    NT 5.1; .NET CLR 1.0.3705)"
    WebReq.KeepAliv e = True
    WebReq.Headers. Set("Pragma", "no-cache")
    WebReq.Timeout = 30000
    WebReq.Method = "POST"
    WebReq.ContentT ype = "applicatio n/x-www-form-urlencoded"
    PostParms = "userNumber=123 45678&password= 87654321&OK=sub mit&"
    & _
    "runmode=SIGN_I N&LAST_ACTIVE_U RL="
    WebReq.ContentL ength = PostParms.Lengt h
    StrmWrtr = New StreamWriter(We bReq.GetRequest Stream)
    StrmWrtr.Write( PostParms)
    StrmWrtr.Close( )
    WebResp = WebReq.GetRespo nse
    StrmRdr = New StreamReader(We bResp.GetRespon seStream)
    HTML = StrmRdr.ReadToE nd.Trim
    StrmRdr.Close()
    WebResp.Close()

    The source for the web page is:

    <meta http-equiv="Pragma" Content="no-cache">
    <meta http-equiv="Expires" Content="Tuesda y, 14-Dec-1971 04:30:00
    GMT">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=ISO-8859-1">
    <title>Intern et Banking Timeout</title> <!-- for non-nav pages -->
    <!--
    <script language="JavaS cript">
    ldt = new Date;
    inSubmit = 0;
    function dofocus() {
    document.Login. userNumber.focu s();
    inSubmit = 0;
    }
    function clear() {
    document.Login. userNumber.valu e = "";
    document.Login. password.value = "";
    dofocus();
    }
    function formField1()
    {
    Ctrl = document.Login. userNumber;
    if (Ctrl.value == "")
    {
    validatePrompt (Ctrl, "Please enter a valid Customer Number.")
    return (false);
    }
    else
    return (true);
    }
    function formField2()
    {
    bName = navigator.appNa me; // get version of Navigator
    bVer = parseInt(naviga tor.appVersion) ;
    // if Netscape 2.0 or below just get out
    if (bName == "Netscape" && bVer < 3)
    return (true);
    Ctrl = document.Login. password;
    if (Ctrl.value == "")
    {
    validatePrompt (Ctrl, "Please enter a Password.")
    return (false);
    }
    else
    return (true);
    }
    function runSubmit (form)
    {
    if (!formField1())
    return false;

    if (!formField2())
    return false;
    // Due to the re-direct from the timeout warning, this no longer
    works.
    // form.LAST_ACTIV E_URL.value = window.location .search;
    document.cookie = "signonValid=TR UE; path=/";
    return true;
    }
    function validatePrompt (Ctrl, PromptStr)
    {
    alert(PromptStr );
    Ctrl.focus();
    return;
    }
    // -->


    </script>
    </head>

    <body bgcolor=white leftmargin=3 onload="dofocus ()">

    <div align="center">
    <br><br>
    <span class="mainTitl e">Internet Banking Timeout</span>

    <form autocomplete="O FF" name="Login" method="post"
    action="./Login.cgi" onsubmit="retur n runSubmit(this) ">

    <table width="500" border="0">
    <tr>
    <td valign="top">

    <span class="subtitle ">For security reasons, your Internet Banking
    session has timed out. Please login again by entering your customer
    number and password here...<BR><BR> If you would like to increase your
    session timeout please do so by clicking on the User Options button
    inside of Internet Banking.</span>

    <br><br>
    </td>
    <td valign="top" width="15"><br> </td>
    <td valign="top">
    <table border="1">
    <tr>
    <td align="center">
    <span class="sectionT itle">Customer Number</span><br>
    <input type="hidden" name="runmode" value="SIGN_IN" >
    <input type="hidden" name="LAST_ACTI VE_URL" value="">&nbsp;
    <input name="userNumbe r" size="16" maxlength="32"> &nbsp;
    </td>
    </tr>
    <tr>
    <td align=center>
    <span class="sectionT itle">Password</span><br>&nbsp;
    <input type="password" name="password" size="16" maxlength="8">
    &nbsp;
    </td>
    </tr>
    <tr>
    <td align="center" valign="middle" >
    <input name="OK" type="submit" value=" Enter ">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>



    </div>

    <!-- end of IB Timeout -->

    </body>
    </html>
  • Joerg Jooss

    #2
    Re: HttpWebRequest: Cookies question

    Jerry Rhodes wrote:[color=blue]
    > When I run the code below, the web server tells me that I need to
    > enable cookies. Can anyone tell me what might be causing that? I'm
    > trying to POST userid and password to their login web page. Thanks!
    >
    > Dim CookieJar As CookieContainer = New CookieContainer ()
    > Dim WebReq As HttpWebRequest
    > Dim WebResp As HttpWebResponse
    > Dim StrmRdr As StreamReader
    > Dim StrmWrtr As StreamWriter
    > Dim PostParms As String
    > Dim URLString As String
    > Dim HTML as String
    > = "https://www.nordstromba nking.com/onlineserv/HB/Login.cgi"
    >
    > WebReq = CType(WebReques t.Create(New Uri(URLString)) ,
    > HttpWebRequest)
    > WebReq.CookieCo ntainer = CookieJar
    > WebReq.Credenti als = CredentialCache .DefaultCredent ials
    > WebReq.UserAgen t = "Mozilla/4.0 (compatible; MSIE 6.0; Windows
    > NT 5.1; .NET CLR 1.0.3705)"
    > WebReq.KeepAliv e = True
    > WebReq.Headers. Set("Pragma", "no-cache")
    > WebReq.Timeout = 30000
    > WebReq.Method = "POST"
    > WebReq.ContentT ype = "applicatio n/x-www-form-urlencoded"
    > PostParms = "userNumber=123 45678&password= 87654321&OK=sub mit&"
    > & _
    > "runmode=SIGN_I N&LAST_ACTIVE_U RL="
    > WebReq.ContentL ength = PostParms.Lengt h
    > StrmWrtr = New StreamWriter(We bReq.GetRequest Stream)
    > StrmWrtr.Write( PostParms)
    > StrmWrtr.Close( )
    > WebResp = WebReq.GetRespo nse
    > StrmRdr = New StreamReader(We bResp.GetRespon seStream)
    > HTML = StrmRdr.ReadToE nd.Trim
    > StrmRdr.Close()
    > WebResp.Close()
    >
    > The source for the web page is:[/color]
    [...][color=blue]
    > function runSubmit (form)
    > {
    > if (!formField1())
    > return false;
    >
    > if (!formField2())
    > return false;
    > // Due to the re-direct from the timeout warning, this no longer
    > works.
    > // form.LAST_ACTIV E_URL.value = window.location .search;
    > document.cookie = "signonValid=TR UE; path=/";[/color]
    ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^

    [color=blue]
    > return true;
    > }[/color]

    Ah, the josys of remote controlling some third-party web app ;-)

    You didn't reverse engineer the web form completely. Your code does not set
    this cookie. Adding it to your cookie container should do the trick.

    Cheers,

    --
    Joerg Jooss
    joerg.jooss@gmx .net


    Comment

    • Jerry Rhodes

      #3
      Re: HttpWebRequest: Cookies question


      Joerg,

      Thank you very, very much for your response. What would a developer in
      the MS world do without Google and people like you??? Your idea got me
      past the cookie question. Now the only HTML I'm getting back is below.
      "HomeBankin g" is the final destination page, but who knows what happened
      in the web server. Thanks again!!
      <html>
      <head>
      <meta http-equiv="refresh" content="25;url =html/JavaScriptError .html">
      <script language="JavaS cript">
      <!--
      location.href = "HomeBanking.cg i";
      // -->
      </script>
      </head>
      <body>
      </body>
      </html>



      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Joerg Jooss

        #4
        Re: HttpWebRequest: Cookies question

        Jerry Rhodes wrote:[color=blue]
        > Joerg,
        >
        > Thank you very, very much for your response. What would a developer
        > in the MS world do without Google and people like you??? Your idea
        > got me past the cookie question. Now the only HTML I'm getting back
        > is below. "HomeBankin g" is the final destination page, but who knows
        > what happened in the web server. Thanks again!![/color]

        Jerry,

        so HomeBanking.cgi gets you there? Great. Never mind the weird architecture
        they're using. When I looked at their home page, I found a number of funny
        things nobody in my team would implement if he knew what's good for him ;-)

        Cheers,

        --
        Joerg Jooss
        joerg.jooss@gmx .net


        Comment

        Working...