The below code allows me to login to a site using HttpWebRequest however I can't login to the site https://www.comsec.com.au (which is the one I want to login to). At the bottom of the code I write the source to a file and upon opening it simply shows the login page.
After looking at the source I believe the issue is caused by the form calling a javascript funciton to actually submit the form when the 'Login' button is clicked. Has anyone had this type of situation in the past and if so what was the solution to get the form to submit?
vb Code:
Dim url As String = "https://www.comsec.com.au/default.aspx" Dim data As String = "UcHeader1$LoginName=MyLogin&UcHeader1$Password=MyPassword&UcHeader1$StartIn=""" Dim buffer As Byte() = Encoding.UTF8.GetBytes(data) Dim result As String = "" Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest) req.Method = "POST" req.ContentType = "application/x-www-form-urlencoded" req.ContentLength = buffer.Length 'req.Proxy = new WebProxy(proxy, true); // ignore for local addresses req.CookieContainer = New CookieContainer() ' enable cookies Dim reqst As Stream = req.GetRequestStream() ' add form data to request stream reqst.Write(buffer, 0, buffer.Length) reqst.Flush() reqst.Close() Console.WriteLine(vbLf & "Posting data to " & url) Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse) ' send request,get response Console.WriteLine(vbLf & "Response stream is: " & vbLf) Dim resst As Stream = res.GetResponseStream() ' display HTTP response Dim sr As New StreamReader(resst) result = sr.ReadToEnd() Using writer As System.IO.StreamWriter = New StreamWriter("C:\startOut.html") writer.Write(result) End Using




Reply With Quote