Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Login through HttpWebRequest?

Login through HttpWebRequest?

Scheduled Pinned Locked Moved Visual Basic
sysadminmcpquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AliAmjad
    wrote on last edited by
    #1

    I actually want to login to a web server on Local Area Network through HttpWebRequest Class, I am using the following code but can't seems to work...

            Dim wr As HttpWebRequest
            Dim wrs As HttpWebResponse
    
    
            wr = CType(WebRequest.Create("http://192.168.2.142/"), HttpWebRequest)
            wr.Method = "POST"
    
            Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..."
            wr.ContentLength = postData.Length
            wr.ContentType = "application/x-www-form-urlencoded"
    
            wr.AllowAutoRedirect = False
    
            Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(postData)
    
            Dim dataStrm As Stream = wr.GetRequestStream()
            dataStrm.Write(buffer, 0, buffer.Length)
            dataStrm.Close()
    
            Try
    
                wrs = wr.GetResponse
    
                Dim sr As New StreamReader(wrs.GetResponseStream)
                Me.rtxtData.Text = sr.ReadToEnd.ToString()
                sr.Close()
    
            Catch ex As Exception
    
                MsgBox(ex.ToString())
    
            End Try
    

    Thanks in advance !

    AliAmjad(MCP) First make it Run THEN make it Run Fast!

    D 1 Reply Last reply
    0
    • A AliAmjad

      I actually want to login to a web server on Local Area Network through HttpWebRequest Class, I am using the following code but can't seems to work...

              Dim wr As HttpWebRequest
              Dim wrs As HttpWebResponse
      
      
              wr = CType(WebRequest.Create("http://192.168.2.142/"), HttpWebRequest)
              wr.Method = "POST"
      
              Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..."
              wr.ContentLength = postData.Length
              wr.ContentType = "application/x-www-form-urlencoded"
      
              wr.AllowAutoRedirect = False
      
              Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(postData)
      
              Dim dataStrm As Stream = wr.GetRequestStream()
              dataStrm.Write(buffer, 0, buffer.Length)
              dataStrm.Close()
      
              Try
      
                  wrs = wr.GetResponse
      
                  Dim sr As New StreamReader(wrs.GetResponseStream)
                  Me.rtxtData.Text = sr.ReadToEnd.ToString()
                  sr.Close()
      
              Catch ex As Exception
      
                  MsgBox(ex.ToString())
      
              End Try
      

      Thanks in advance !

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      AliAmjad wrote:

      Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..."

      You're joking, right?? This website requires you to send the username and password IN PLAIN TEXT in the URL string?? So much for security... Without knowing what the website requires, or how you login to it, it's impossible to tell you how to fix this. Everything depends on how the website works.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        AliAmjad wrote:

        Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..."

        You're joking, right?? This website requires you to send the username and password IN PLAIN TEXT in the URL string?? So much for security... Without knowing what the website requires, or how you login to it, it's impossible to tell you how to fix this. Everything depends on how the website works.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        A Offline
        A Offline
        AliAmjad
        wrote on last edited by
        #3

        :-D Actually this is the only line in code i don't understand how to arrange the post data, I saw some examples but can't seems to work as far as website goes it's an Easy File Sharing web server http://www.sharing-file.com/ on LAN, read their whole site but didn't find the solution i think they receive username and password in plain text. But again I have made a login form in ASP.NET and then tried to login there but again can't! what's the problem is there something wrong with my code???

        AliAmjad(MCP) First make it Run THEN make it Run Fast!

        D 1 Reply Last reply
        0
        • A AliAmjad

          :-D Actually this is the only line in code i don't understand how to arrange the post data, I saw some examples but can't seems to work as far as website goes it's an Easy File Sharing web server http://www.sharing-file.com/ on LAN, read their whole site but didn't find the solution i think they receive username and password in plain text. But again I have made a login form in ASP.NET and then tried to login there but again can't! what's the problem is there something wrong with my code???

          AliAmjad(MCP) First make it Run THEN make it Run Fast!

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          How does the site ask for a username and password?? Is it in a web page?? Is it in a small popup window?? How??

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          A 1 Reply Last reply
          0
          • D Dave Kreskowiak

            How does the site ask for a username and password?? Is it in a web page?? Is it in a small popup window?? How??

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            A Offline
            A Offline
            AliAmjad
            wrote on last edited by
            #5

            here is the screen shot and its not a secure edition too: http://yehpal.googlepages.com/login.JPG[^]

            AliAmjad(MCP) First make it Run THEN make it Run Fast!

            D 1 Reply Last reply
            0
            • A AliAmjad

              here is the screen shot and its not a secure edition too: http://yehpal.googlepages.com/login.JPG[^]

              AliAmjad(MCP) First make it Run THEN make it Run Fast!

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              OK. You can't take the approach you're using to fill in the username and password. You have to write code that gets this page, then finds the username and passwords HTML input boxes in the form, fill them in, then "click" on the Login! button to submit the filled in page back to the webserver.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              A 1 Reply Last reply
              0
              • D Dave Kreskowiak

                OK. You can't take the approach you're using to fill in the username and password. You have to write code that gets this page, then finds the username and passwords HTML input boxes in the form, fill them in, then "click" on the Login! button to submit the filled in page back to the webserver.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                A Offline
                A Offline
                AliAmjad
                wrote on last edited by
                #7

                Thanks for putting me in a right direction but can you please give me a hint which class i should use to fill the input boxes and to invoke the click event of Login button.

                AliAmjad(MCP) First make it Run THEN make it Run Fast!

                D 1 Reply Last reply
                0
                • A AliAmjad

                  Thanks for putting me in a right direction but can you please give me a hint which class i should use to fill the input boxes and to invoke the click event of Login button.

                  AliAmjad(MCP) First make it Run THEN make it Run Fast!

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Sorry, but you use a Web Browser control to do this.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

                  A 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Sorry, but you use a Web Browser control to do this.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007, 2008

                    A Offline
                    A Offline
                    AliAmjad
                    wrote on last edited by
                    #9

                    Thank you very much I'll try to figure it out.

                    AliAmjad(MCP) First make it Run THEN make it Run Fast!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups