Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post XmlDocument via HTTP

Status
Not open for further replies.

reffek

Programmer
Apr 7, 2005
24
US
I was wondering how to post an XMLDocument via HTTP using System.Xml. The response will be synchronous.

With MSXML it's simple, you just use:

Dim xmlSender As New MSXML2.XMLHTTP
xmlSender.open("POST", urlToPostTo, False)
xmlSender.send(xmlToSend.xml)

However, I can't find how to do it with System.Xml instead of MSXML. What's the System.Xml equivalent of MSXML2.XMLHTTP?

 
Okay, I think I figured it out:

xml is being passed here as a string of the XML doc.

Dim xmlURI As New Uri(urlToPostTo)
Dim xmlSender As HttpWebRequest = HttpWebRequest.Create(xmlURI)
xmlSender.Method = "POST"
xmlSender.ContentType = "application/x-Dim xmlStream As Stream = xmlSender.GetRequestStream()
Dim xmlBytes() As Byte = Encoding.UTF8.GetBytes(xml)
xmlStream.Write(xmlBytes, 0, xmlBytes.Length)
xmlStream.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top