How do I make my VB.net code perform an html form POST

Mar 7 2006 3:01 PM
How can I make my VB.NET code behind perform the following:

<form name="form1" method="post" action="http://tstwp1pas1/express/default.aspx">
<table width="100%" border="0" align="center"cellpadding="4" cellspacing="0">
<tr>
<td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Please wait while page loads.</strong></font></div></td>
</tr></table>
<!-- Change the 'value' attribute for both username and password to use valid credentials -->
<input name="_username" type="hidden" id="_username" value="XYZ">
<input name="_password" type="hidden" id="_password" value="XYZ123">
<input name="_QuoteID" type="hidden" id="_QuoteID">
<input name="_submitAction" type="hidden" id="_submitAction" value="load">
<input name="_targetPage" type="hidden" id="_targetPage" value="interview">
</
form>

I am using WebRequest and WebResponse can someone tell me what's wrong with what I have so far.

Dim myRequest As WebRequest = WebRequest.Create(http://tstwp1pas1/express/default.aspx)

myRequest.Headers("_userName") = "admin"

myRequest.Headers("_password") = "admin"

myRequest.Headers("_QuoteID") = "133"

myRequest.Headers("_submitAction") = "load"

myRequest.Headers("_targetPage") = "interview"

myRequest.Method = "POST"

myRequest.ContentType = "text/html"

myRequest.ContentLength = 0

Dim myResponse As WebResponse = myRequest.GetResponse()

Dim ReceiveStream As System.IO.Stream = myResponse.GetResponseStream()

Dim MyEncoding As Encoding = Encoding.GetEncoding("utf-8")

Dim ReadStream As StreamReader = New StreamReader(ReceiveStream, MyEncoding)

Dim str As String = ReadStream.ReadToEnd

Dim temp As String = myRequest.GetResponse.ResponseUri.ToString

ReadStream.Close()

myResponse.Close()

Response.Write(str)

Response.Flush()