I have an ActiveX that POSTs to the server (HTTP Handler) with a payload of a certain XML document.
Is there a better way to retrieve the payload into XML than the below?
private static byte[] RequestPayload()
{
int bytesToRead = HttpContext.Current.Request.TotalBytes;
return (HttpContext.Current.Request.BinaryRead(bytesToRead));
}
using (var mem = new MemoryStream(RequestPayload()))
{
var docu = XDocument.Load(mem);
}
Once I have the "docu" I can query using LINQ to XML.
Thanks
Simply load the XML from the InputStream of the Request e.g.
XDocument doc;
using (Stream input = HttpContext.Current.Request.InputStream)
{
doc = XDocument.Load(input);
}
there is no need for a MemoryStream in my view.
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