Dim LOGIN_URL As String = "http://xxxx/Signin.aspx"
Dim MyWebRequest As HttpWebRequest = WebRequest.Create(LOGIN_URL)
Dim responseReader = New StreamReader(MyWebRequest.GetResponse().GetResponseStream())
Dim responseData As String = responseReader.ReadToEnd
responseReader.Close()
Dim viewState As String = ExtractViewState(responseData)
Dim postData As String = String.Format("__VIEWSTATE={0}&TxtUsername={1}&TxtPassword={2}&btnLogin=Login", viewState, "MyUsername", "mypass")
Dim encoding As New System.Text.ASCIIEncoding()
Dim by As Byte() = encoding.GetBytes(postData)
Dim cookies As CookieContainer = New CookieContainer()
MyWebRequest = WebRequest.Create(LOGIN_URL)
MyWebRequest.Method = "POST"
MyWebRequest.ContentLength = by.Length
' responseReader = New StreamReader(MyWebRequest.GetResponse().GetResponseStream())
' responseData = responseReader.ReadToEnd()
MyWebRequest.ContentType = "application/x-www-form-urlencoded"
MyWebRequest.CookieContainer = cookies
Dim requestWriter As StreamWriter = New StreamWriter(MyWebRequest.GetRequestStream())
requestWriter.Write(postData)
requestWriter.Close()
MyWebRequest.GetResponse().Close()
MyWebRequest = WebRequest.Create(LOGIN_URL)
MyWebRequest.CookieContainer = cookies
responseReader = New StreamReader(MyWebRequest.GetResponse().GetResponseStream())
responseData = responseReader.ReadToEnd()
responseReader.Close()