Imports System.Net
Imports System.Text
Imports System.IO
Public Class Form1
Dim logincookie As CookieContainer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim postData As String = "memberid=" & TextBox1.Text & "&userid=undefined&password=" & TextBox2.Text & "&captcha=undefined"
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://www.gamagic.com/user/login_chk"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = "http://www.gamagic.com/user/login_chk"
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
System.Threading.Thread.Sleep(1000)
WebBrowser1.Navigate("http://www.gamagic.com", False, byteData, "")
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
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
WebBrowser1.DocumentText = RichTextBox2.Text
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://www.gamagic.com/forum/forum.php?mod=forumdisplay&fid=122"), HttpWebRequest)
request.CookieContainer = logincookie
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim reader As New StreamReader(response.GetResponseStream())
Dim theusercp As String = reader.ReadToEnd
RichTextBox2.Text = theusercp
WebBrowser1.Navigate("http://www.gamagic.com/forum/forum.php?mod=forumdisplay&fid=122")
End Sub
Private Sub Button5Home_Click(sender As Object, e As EventArgs) Handles Button5.Click
WebBrowser1.Navigate("http://www.gamagic.com")
End Sub
Private Sub Button7Forward_Click(sender As Object, e As EventArgs) Handles Button7.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button6Back_Click(sender As Object, e As EventArgs) Handles Button6.Click
WebBrowser1.GoBack()
End Sub
End Class
Tag : .NET, VBScript, Win (Windows App), VB.NET
Date :
2013-05-08 11:13:36
By :
polahog
View :
1508
Reply :
2
No. 1
Guest
see : http://stackoverflow.com/questions/2830586/setting-a-cookie-in-a-webbrowser-control