Sending xml over http loses indents



I have a fairly large XML file that I want to send over http to a device. The method I am using is creating the Xmldocument (called doc), converting the outerXML to a string, and sending it using an HttpWebResponse.


Here's a portion of the XML:



<MotionDetection>
<id>1</id>
<enabled>true</enabled>
<samplingInterval>2</samplingInterval>
<startTriggerTime>500</startTriggerTime>
<endTriggerTime>500</endTriggerTime>
<regionType>grid</regionType>
<Grid>
<rowGranularity>15</rowGranularity>
<columnGranularity>22</columnGranularity>
</Grid>
</MotionDetection>


The Problem: Whenever I send my code over the internet, it doesn't accept it (giving me a bad request response) because the xml is missing the "indents" or vbCrlfs that cause the wireshark sniffer to see it like an xml instead of a bunch of strings smashed together.


Is there a way to send it using httpwebresponse so that those stay within the request? Other than, of course, breaking up the string and inserting it by "hand"?


Here's my current code, since I also tried it using an upload client instead of httpwebrequest.



Dim doc As New Xml.XmlDocument
doc.Load("test.xml")
Try
Dim url = "http://" & currentCamera.ipaddr & "/Custom/Motion"
Dim client As New WebClient
client.Credentials = New Net.NetworkCredential(currentCamera.Username, currentCamera.Password)
Dim sentXml As Byte() = System.Text.Encoding.ASCII.GetBytes(doc.OuterXml)
Dim response2 As Byte() = client.UploadData(url, "PUT", sentXml)

Catch ex As Exception

End Try

No comments:

Post a Comment