Login to a site using HttpWebRequest VB.NET Issue!

Joined
Sep 7, 2012
Messages
4
Reaction score
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!
 
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.
 
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.
 
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.
 
Thank you guys! It helped. I will try these suggestions and keep you updated!
 
Back
Top