Question How to Login to multiple sites(POST method and referer)

musiccrave

New member
Joined
Jan 21, 2012
Messages
1
Programming Experience
Beginner
hi guys,

This is my first post.

I've followed this tutorial and i want to modify it a little bit. And the author, i think is very busy.

Here is the code he got:


Imports System.Net
Imports System.Text
Imports System.IO

Public Class Form1

Dim logincookie As CookieContainer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim postData As String = "referer=http%3A%2F%2Fforums.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3Dglobal%26section%3Dlogin&username=" & TextBox1.Text & "&password=" & TextBox2.Text & "&rememberMe=1"
Dim tempCookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)

Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://forums.zybez.net/index.php?app=core&module=global&section=login&do=process"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = "http://forums.zybez.net/index.php?app=core&module=global&section=login&do=process"
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

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WebBrowser1.DocumentText = RichTextBox1.Text
End Sub
End Class


What I want to do is I want to post to different referers one at a time and of course the links will be provided by a richtextbox(i.e. richtextbox1.lines(i) ). I will use only password(which will be chosen by the user from a combobox(combobox1.text)) because the username is harcoded. This is what so far ive come up with but it always gives me the result of the first line(or referer) from richtextbox1. I think there might be a problem with my "FOR" code.


Function login(ByRef link As String) As String
For i As Integer = 0 To RichTextBox1.Lines.Length - 1
Dim postdata As String = ComboBox1.Text
Dim tempCookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postdata)

Dim links As String = RichTextBox1.Lines(i)
If links <> "" Then
Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create(links), HttpWebRequest)

postReq.Method = "POST"
postReq.KeepAlive = true
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = links(i)
postReq.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"
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
richtextbox2.text = the page

Else
MessageBox.Show("encountered a blank line...skipping")
End If

Next

End Function


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
login(1)
End Sub



Any help or enlightenment for a newbie would be greatly appreciated. Thanks in advanced

Cheers,

musiccrave
 
Top Bottom