I am trying to send an xml string through an HTTP request, and receive it on the other end. On the receiving end, I am always getting that the xml is null. Can you tell me why that is?
Send:
var url = "http://website.com";
var postData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><xml>...</xml>";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postData);
var req = (HttpWebRequest)WebRequest.Create(url);
req.ContentType = "text/xml";
req.Method = "POST";
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
string response = "";
using (System.Net.WebResponse resp = req.GetResponse())
{
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
response = sr.ReadToEnd().Trim();
}
}
Receive:
[HttpPost]
[ValidateInput(false)]
public ActionResult Index(string xml)
{
//xml is always null
...
return View(model);
}