I am trying to post an XMLDocument
to an URL. This is what I have so far:
var uri = System.Configuration.ConfigurationManager.AppSettings["Url"];
var template = System.Configuration.ConfigurationManager.AppSettings["Template"];
XmlDocument reqTemplateXml = new XmlDocument();
reqTemplateXml.Load(template);
reqTemplateXml.SelectSingleNode("appInfo/appNumber").InnerText = x;
reqTemplateXml.SelectSingleNode("appInfo/coappNumber").InnerText = y;
WebRequest req = null;
WebResponse rsp = null;
req = WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "text/xml";
rsp = req.GetResponse();
What I am trying to figure out is how to load this XmlDocument
to the WebRequest
object so that it can be posted to that URL.
If you want to send XML data to the server, set the Request Header correctly to be read by the sever as XML. xmlhttp. setRequestHeader('Content-Type', 'text/xml'); Use the send() method to send the request, along with any XML data.
The REST API Client Service currently accepts only JSON input when making REST API Create, Read, Update, or Delete requests. It is nevertheless possible to use XML input when making REST API requests.
To post XML using Curl, you need to pass XML data to Curl with the -d command line parameter and specify the data type in the body of the POST request message using the -H Content-Type: application/xml command line parameter.
General applications: XML provides a standard method to access information, making it easier for applications and devices of all kinds to use, store, transmit, and display data.
you need to write to the RequestStream before calling req.GetResponse()
like this.
using (var writer = new StreamWriter(req.GetRequestStream()))
{
writer.Write(xml);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With