I am sending information to a webpage using the httpwebrequest object. When I
send a simple string (i.e. "message-test") it works fine. I changed it to
send an XML document by encoding it and adding it to the stream now I get an
internal 500 error when I try to get the response. Could you please let me
know what I am doing wrong. The code is as shown below.
Thanks
Dim objRequest As HttpWebRequest =
WebRequest.Create("http://localhost/VBWebPlayground/XMLTrans.aspx")
Dim XmlString As String
'Load XML into String
Dim docReader As System.IO.StreamReader = New
System.IO.StreamReader("c:\testinv2.xml")
XmlString = docReader.ReadToEnd()
docReader.Close()
' setup HTTP header
objRequest.ContentType = "application/x-www-form-urlencoded"
objRequest.KeepAlive = False
objRequest.Method = "POST"
objRequest.ProtocolVersion = HttpVersion.Version10
'encode XML document
Dim encXML As Byte() =
System.Text.Encoding.GetEncoding(1252).GetBytes(Xm lString)
objRequest.ContentLength = encXML.Length
'Send information to webpage via stream object
Dim stmWriter As System.IO.Stream = objRequest.GetRequestStream()
stmWriter.Write(encXML, 0, encXML.Length) 'XmlString) '&
Try
stmWriter.Close()
Catch exp As System.Exception
label1.Text = "Request=" & exp.Message
End Try
'Get response stream to complete transmition
Dim rsp As HttpWebResponse
Try
rsp = objRequest.GetResponse()
Catch exp As System.Exception
label1.Text = "Response=" & exp.Message
End Try