1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Login to a site using HttpWebRequest VB.NET Issue!

Discussion in 'Visual Basic .NET' started by thealiengameplay, Jul 26, 2013.

  1. thealiengameplay

    thealiengameplay Newbie

    Joined:
    Sep 7, 2012
    Messages:
    4
    Likes Received:
    0
    Hi!
    I know that there is a lot of http web request tutorials on how to login into a website but I tried most of them and they don't work :(.
    What i want to do is go to a likes exchange website rootdomain/login.php and login with the username and password located in the textbox1 and 2.
    I cant post links but the name of the site is likesasap. If someone can help me, it would be great! Also, if I finish my bot, I will share it here for free!

    My bot will login to the site, go to a custom page and like facebook pages for points!
    After that, if the bot is stable, I will add more features!
    Right now, I need to know how to login with all the cookies and that stuff...

    Thanks!
     
  2. theMagicNumber

    theMagicNumber Regular Member

    Joined:
    May 13, 2010
    Messages:
    345
    Likes Received:
    195
    • Thanks Thanks x 1
  3. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,113
    Likes Received:
    1,712
    Location:
    Banana Republic
    You need to explain more about the issue. And as previous poster said analyze fiddler or wireshark logs to know what is being sent and received from the browser (like cookies/sessions) which you are missing in the HTTP request.
     
  4. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    Actually using httpwebrequest is a pretty straight forward process. You can build your post by first going to the website that you want to automate using a browser like Firefox and download the plug in called LiveHttpHeaders. Once at the main screen you will want to fill out the username, password text boxes on the screen. Before you hit Log-In under tools > turn on LiveHttpHeaders and then turn on capture and hit the log-in button. Your going to be looking for your POST to the site with your username password in the text.

    For mine it was this: "username="& Username.text & "&pass="& Password.Text & "&login=Login&r="

    I rigged it up assuming your username is going to have an input box called Username and a password box called Password.

    When you press your submit button your screen sends the entire POST all at once.
     
  5. stevie

    stevie Newbie

    Joined:
    Jul 31, 2010
    Messages:
    48
    Likes Received:
    10
    Location:
    UK
    Home Page:
    Here is an example:

    Code:
    
    
            Dim postData As String = "Post Data Here"
            Dim tempCookies As New CookieContainer
            Dim encoding As New UTF8Encoding
            Dim byteData As Byte() = encoding.GetBytes(postData)
    
            Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("Website Login URL Here"), HttpWebRequest)
            postReq.Method = "POST"
            postReq.KeepAlive = True
            postReq.CookieContainer = tempCookies
            postReq.ContentType = "application/x-www-form-urlencoded"
            postReq.Referer = "Website Login URL Here"
            postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
            postReq.ContentLength = byteData.Length
    
            Dim postreqstream As Stream = postReq.GetRequestStream()
            postreqstream.Write(byteData, 0, byteData.Length)
            postreqstream.Close()
            Dim postresponse As HttpWebResponse
    
            postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
            tempCookies.Add(postresponse.Cookies)
            logincookie = tempCookies
            Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
    
            Dim thepage As String = postreqreader.ReadToEnd
    
            RichTextBox1.Text = thepage
    
    I hope it helps.
     
  6. thealiengameplay

    thealiengameplay Newbie

    Joined:
    Sep 7, 2012
    Messages:
    4
    Likes Received:
    0
    Thank you guys! It helped. I will try these suggestions and keep you updated!