S
Shawn
Hi.
I'm trying to post a form from my code.
I've created a simple page (page_2.asp):
<html>
<body>
<%
response.write(request.form("username"))
%>
</body>
</html>
Now, here is the code i'm using to try and post to this page:
Dim req As HttpWebRequest
Dim resp As WebResponse
Dim data() As Byte
Dim form_post_data As String
Dim encoding As System.Text.ASCIIEncoding = New
System.Text.ASCIIEncoding
Dim sr As IO.StreamReader
form_post_data = "&username=" & "test" & "&password=" & "test"
data = encoding.GetBytes(form_post_data)
req = CType(WebRequest.Create("http://localhost/tmp/asp/page_2.asp"),
HttpWebRequest)
Try
req.Method = "POST"
req.KeepAlive = True
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = data.Length
Dim newStream As IO.Stream
newStream = req.GetRequestStream()
newStream.Write(data, 0, data.Length)
newStream.Close()
resp = CType(req.GetResponse(), HttpWebResponse)
sr = New IO.StreamReader(resp.GetResponseStream())
Dim result As String = sr.ReadToEnd()
sr.Close()
resp.Close()
Catch ex As Exception
End Try
result should contain:
<html>
<body>
test
</body>
</html>
But instead it just returns the html and body tag. What am I doing wrong
here?
Any help is greatly appreciated!!
Shawn
I'm trying to post a form from my code.
I've created a simple page (page_2.asp):
<html>
<body>
<%
response.write(request.form("username"))
%>
</body>
</html>
Now, here is the code i'm using to try and post to this page:
Dim req As HttpWebRequest
Dim resp As WebResponse
Dim data() As Byte
Dim form_post_data As String
Dim encoding As System.Text.ASCIIEncoding = New
System.Text.ASCIIEncoding
Dim sr As IO.StreamReader
form_post_data = "&username=" & "test" & "&password=" & "test"
data = encoding.GetBytes(form_post_data)
req = CType(WebRequest.Create("http://localhost/tmp/asp/page_2.asp"),
HttpWebRequest)
Try
req.Method = "POST"
req.KeepAlive = True
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = data.Length
Dim newStream As IO.Stream
newStream = req.GetRequestStream()
newStream.Write(data, 0, data.Length)
newStream.Close()
resp = CType(req.GetResponse(), HttpWebResponse)
sr = New IO.StreamReader(resp.GetResponseStream())
Dim result As String = sr.ReadToEnd()
sr.Close()
resp.Close()
Catch ex As Exception
End Try
result should contain:
<html>
<body>
test
</body>
</html>
But instead it just returns the html and body tag. What am I doing wrong
here?
Any help is greatly appreciated!!
Shawn