G
Guest
Why is .NET leaving out the POST data on my HTTPWebRequest?
I had some code working fine in VS2002 and when I moved to VS2003 it doesn't
seem to be adding the POST data. So I took the same chunk of code and
placed it in VS2005 Beta 1 (on a different machine), and it works there as
well.
When I run the code below in my VS2003 and view the request packet with a
sniffer it is missing th POST content (firstone=Hello World)
Thanks,
Travis
..NET (version 1.1.4322.573)
Imports System.IO
Imports System.Net
Imports System.Text
Module Module1
Sub Main()
System.Net.ServicePointManager.Expect100Continue = False
Dim myReq As HttpWebRequest = _
WebRequest.Create("http://www.contoso.com/codesnippets/next.asp")
Dim postData As String = "firstone" + ChrW(61) + "Hello World"
Dim encoding As New ASCIIEncoding
Dim byte1 As Byte() = encoding.GetBytes(postData)
' Set the content type of the data being posted.
myReq.ContentType = "application/x-www-form-urlencoded"
myReq.Method = "POST"
' Set the content length of the string being posted.
myReq.ContentLength = postData.Length
Dim newStream As Stream = myReq.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
newStream.Close()
Dim myResponse As HttpWebResponse = myReq.GetResponse()
End Sub
End Module
I had some code working fine in VS2002 and when I moved to VS2003 it doesn't
seem to be adding the POST data. So I took the same chunk of code and
placed it in VS2005 Beta 1 (on a different machine), and it works there as
well.
When I run the code below in my VS2003 and view the request packet with a
sniffer it is missing th POST content (firstone=Hello World)
Thanks,
Travis
..NET (version 1.1.4322.573)
Imports System.IO
Imports System.Net
Imports System.Text
Module Module1
Sub Main()
System.Net.ServicePointManager.Expect100Continue = False
Dim myReq As HttpWebRequest = _
WebRequest.Create("http://www.contoso.com/codesnippets/next.asp")
Dim postData As String = "firstone" + ChrW(61) + "Hello World"
Dim encoding As New ASCIIEncoding
Dim byte1 As Byte() = encoding.GetBytes(postData)
' Set the content type of the data being posted.
myReq.ContentType = "application/x-www-form-urlencoded"
myReq.Method = "POST"
' Set the content length of the string being posted.
myReq.ContentLength = postData.Length
Dim newStream As Stream = myReq.GetRequestStream()
newStream.Write(byte1, 0, byte1.Length)
newStream.Close()
Dim myResponse As HttpWebResponse = myReq.GetResponse()
End Sub
End Module