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:
  1. Dim url As String = "https://www.comsec.com.au/default.aspx"
  2.         Dim data As String = "UcHeader1$LoginName=MyLogin&UcHeader1$Password=MyPassword&UcHeader1$StartIn="""
  3.    
  4.         Dim buffer As Byte() = Encoding.UTF8.GetBytes(data)
  5.         Dim result As String = ""
  6.         Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
  7.         req.Method = "POST"
  8.         req.ContentType = "application/x-www-form-urlencoded"
  9.         req.ContentLength = buffer.Length
  10.         'req.Proxy = new WebProxy(proxy, true); // ignore for local addresses
  11.         req.CookieContainer = New CookieContainer()
  12.         ' enable cookies
  13.         Dim reqst As Stream = req.GetRequestStream()
  14.         ' add form data to request stream
  15.         reqst.Write(buffer, 0, buffer.Length)
  16.         reqst.Flush()
  17.         reqst.Close()
  18.  
  19.         Console.WriteLine(vbLf & "Posting data to " & url)
  20.         Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
  21.         ' send request,get response
  22.         Console.WriteLine(vbLf & "Response stream is: " & vbLf)
  23.         Dim resst As Stream = res.GetResponseStream()
  24.         ' display HTTP response
  25.         Dim sr As New StreamReader(resst)
  26.         result = sr.ReadToEnd()
  27.         Using writer As System.IO.StreamWriter = New StreamWriter("C:\startOut.html")
  28.             writer.Write(result)
  29.         End Using