471,337 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

httpWebrequest error

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
Jul 28 '05 #1
0 883

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Gregory A Greenman | last post: by
10 posts views Thread by Gregory A Greenman | last post: by
10 posts views Thread by Gregory A Greenman | last post: by
2 posts views Thread by =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.