Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 从HTTP POST请求负载中检索XML_Asp.net_Linq To Xml - Fatal编程技术网

Asp.net 从HTTP POST请求负载中检索XML

Asp.net 从HTTP POST请求负载中检索XML,asp.net,linq-to-xml,Asp.net,Linq To Xml,我有一个ActiveX,它向服务器(HTTP处理程序)发送一个特定XML文档的负载 有没有比下面更好的方法将有效负载检索到XML中 private static byte[] RequestPayload() { int bytesToRead = HttpContext.Current.Request.TotalBytes; return (HttpContext.Current.Request.BinaryRead(bytesToRead)); } using (var mem

我有一个ActiveX,它向服务器(HTTP处理程序)发送一个特定XML文档的负载

有没有比下面更好的方法将有效负载检索到XML中

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);
}
一旦有了“docu”,我就可以使用linqtoxml进行查询


谢谢

只需从请求的输入流加载XML即可

XDocument doc;
using (Stream input = HttpContext.Current.Request.InputStream)
{
  doc = XDocument.Load(input);
}

在我看来,不需要记忆流。

谢谢!我的案例必须有一个byte[]而不是流。以防您不使用4.0框架: