VS 2008 Login onto a website-VBForums
Results 1 to 13 of 13

Thread: Login onto a website

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Question Login onto a website

    I'm working on a community application for displaying active members and more.
    I know how to do this. (using webbrowser, getting html code )
    But to see this section, you must log in.

    It regards this website: http://productions.lostpirates.co.uk/

    I tried everything, even html editing, but nothing helped.
    How can I using vb .net (maybe html) login onto a website?

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: Login onto a website

    Hey,

    You should be able to use the HttpWebRequest:

    http://msdn.microsoft.com/en-us/libr...ebrequest.aspx

    Which allows you to specify the Credentials that you want to use in the Request:

    http://msdn.microsoft.com/en-us/libr...edentials.aspx

    Hope that helps!!

    Gary

  3. #3
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: Login onto a website

    Use a program or add-on (such as Firebug or Tamper Data) to find the post data when you login to the site, then encode it using System.Text.Encoding.UTF8.GetBytes().
    After doing so you can call the navigate method of the webbrowser control with the post data appended to the link.

    This is just one way that I know about, I'm sure there are plenty more.

  4. #4
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Re: Login onto a website

    If you are using vb 06 then this might help > http://www.youtube.com/watch?v=ojN1QCP_c1g

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Login onto a website

    Quote Originally Posted by allstarsdied4me View Post
    If you are using vb 06 then this might help > http://www.youtube.com/watch?v=ojN1QCP_c1g
    Seeing as this is the .NET forum, I'd be surprised if he used VB6. Especially since he specifically mentions using VB.NET in the first post
    ---My Flickr photo (mostly screenshots these days!) stream. Have a look!

    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    TCP client/server connection | Retrieving the EventHandler for any Event by code.
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: Login onto a website

    Quote Originally Posted by allstarsdied4me View Post
    If you are using vb 06 then this might help > http://www.youtube.com/watch?v=ojN1QCP_c1g
    If he is using VB 06, then he is posting in the wrong forum, and should ask for the thread to be removed.

    Gary

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Login onto a website

    I managed to send a http request.

    Code I use now:

    Declarations:
    Imports System.Net
    Imports System.IO

    Code:
            Dim myWebReq As HttpWebRequest
            Dim myWebResp As HttpWebResponse
            Dim encoding As New System.Text.ASCIIEncoding()
            Dim data() As Byte
            Dim postData As String = ""
            Dim sr As StreamReader
            Dim sw As StreamWriter
            postData += "txtUsername=bergerkiller"
            postData += "&"
            postData += "txtPassword=password"
            Data = encoding.GetBytes(postData)
            myWebReq = WebRequest.Create("http://productions.lostpirates.co.uk/")
            myWebReq.Method = "POST"
            myWebReq.ContentType = "application/x-www-form-urlencoded"
            myWebReq.ContentLength = data.Length
            Dim myStream As Stream = myWebReq.GetRequestStream()
            myStream.Write(data, 0, data.Length)
            myStream.Close()
            myWebResp = myWebReq.GetResponse
            sr = New StreamReader(myWebResp.GetResponseStream)
            Dim strHTML As String = sr.ReadToEnd
            sw = File.CreateText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.htm")
            sw.WriteLine(strHTML)
            sw.Close()
    But I still can't log in. What should I do
    Please help me out.
    Last edited by bergerkiller; Aug 25th, 2009 at 11:37 AM.

  8. #8
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: Login onto a website

    myWebReq = WebRequest.Create("http://productions.lostpirates.co.uk/")
    is that the exact address of the login page? I'm not familiar with webrequest, but logically it would seem that you would need to be on the exact page which holds the login screen.

  9. #9
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: Login onto a website

    Here are the post parameters:


    The post data would be something along the lines of:
    Code:
    Dim postData As String = "username=UsernameHere&user_password=MyPassword&op=login"
    Encoding.ASCII.GetBytes(postData)

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Login onto a website

    Lol, how did you get that console?
    Oh and, I can't use 'keep-alive", it gave me an error:
    "Keep-Alive and Close can't be inherited with this property.
    parameter name: value"

    (translated from dutch)

    Code:
    Dim myWebReq As HttpWebRequest
            Dim myWebResp As HttpWebResponse
            Dim encoding As New System.Text.ASCIIEncoding()
            Dim data() As Byte
            Dim sr As StreamReader
            Dim sw As StreamWriter
            Dim postData As String = "username=Username&user_password=UserPass&op=login"
            data = encoding.ASCII.GetBytes(postData)
            myWebReq = WebRequest.Create("http://productions.lostpirates.co.uk/")
            myWebReq.Accept = "Text/Html,application/xhtml+xml"
            myWebReq.Method = "POST"
            myWebReq.ContentLength = data.Length
            myWebReq.UserAgent = "Mozilla/5.0"
            myWebReq.Connection = "keep-alive"
            myWebReq.KeepAlive = 300
            myWebReq.Referer = "http://productions.lostpirates.co.uk/"
            Dim myStream As Stream = myWebReq.GetRequestStream()
            myStream.Write(data, 0, data.Length)
            myStream.Close()
            myWebResp = myWebReq.GetResponse
            sr = New StreamReader(myWebResp.GetResponseStream)
            Dim strHTML As String = sr.ReadToEnd
            sw = File.CreateText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.htm")
            sw.WriteLine(strHTML)
            sw.Close()
    What should I do?

  11. #11
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: Login onto a website

    I suppose you can just leave the keep alive property out and see if it sets a default value.

    Oh, and that window is Tamper Data, an add-on for Firefox.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Login onto a website

    Ah thanks. I downloaded and installed tamper data.
    It seems to be a nice program.

    I'll experiment a little with it. (especially postdata function)

  13. #13
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,962

    Re: Login onto a website

    Hey,

    Another application that you may be interested in is ieHttpHeaders. It is an add-in for Internet Explorer, it simply let's you inspect the HTTP Headers that are being sent and received. It is a very simple interface, and let's you see what post data you would need to send along with the request.

    Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.