Help!
I need to post an xml string to a server. I've almost got it working but a couple of things are proving difficult. Here is the code (where 'output' is a string of xml):
The requirements for the post are that the data must be sent in a POST parameter called "XMLDATA=" the xmldata must be URL encoded, but the XMLDATA= part must not.
Currently I have commented out the code that I thought would URL encode the string of XML - But if I use that line the web server returns an error stating : <RequestResultText>XML-error Stopping after fatal error: The markup in the document preceding the root element must be well-formed.</RequestResultText>
Basically the above code does work except even though there is no XMLDATA= parameter (god knows how!). However the formatting is wrong as the carriage returns are not displayed.
How do I add the POST Parameter and also url Encode the output/XML string ?
Hope this made sense!
Cheers
Darren
I need to post an xml string to a server. I've almost got it working but a couple of things are proving difficult. Here is the code (where 'output' is a string of xml):
Code:
Dim Gateways(1) As String
Gateways(0) = "[URL unfurl="true"]http://xml3.mblox.com:8180/send"[/URL]
Gateways(1) = "[URL unfurl="true"]http://xml4.mblox.com:8180/send"[/URL]
'output = HttpUtility.UrlEncode(output)
Dim web As New WebClient
web.Headers.Add("Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded")[/URL]
Dim postData As Byte() = System.Text.Encoding.ASCII.GetBytes(output)
For Each gWay As String In Gateways
Dim response As Byte() = web.UploadData(gWay, postData)
Console.Write(System.Text.Encoding.ASCII.GetString(response))
Dim respXml As New XmlDocument
respXml.LoadXml(System.Text.Encoding.ASCII.GetString(response))
If respXml.SelectSingleNode("//RequestResultCode").InnerText = "0" Then ' success, exit loop
MessageBox.Show("Message sent successfully", "pnrSMS Send Results", MessageBoxButtons.OK, MessageBoxIcon.Information)
web.Dispose()
Exit For
End If
Next
The requirements for the post are that the data must be sent in a POST parameter called "XMLDATA=" the xmldata must be URL encoded, but the XMLDATA= part must not.
Currently I have commented out the code that I thought would URL encode the string of XML - But if I use that line the web server returns an error stating : <RequestResultText>XML-error Stopping after fatal error: The markup in the document preceding the root element must be well-formed.</RequestResultText>
Basically the above code does work except even though there is no XMLDATA= parameter (god knows how!). However the formatting is wrong as the carriage returns are not displayed.
How do I add the POST Parameter and also url Encode the output/XML string ?
Hope this made sense!
Cheers
Darren