从 HTTP POST 请求负载中检索 XML

发布于 2024-10-31 18:33:08 字数 439 浏览 0 评论 0原文

我有一个 ActiveX,它使用某个 XML 文档的有效负载 POST 到服务器(HTTP 处理程序)。

有没有比下面更好的方法将有效负载检索到 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”,我就可以使用 LINQ to XML 进行查询。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒浓于脸红 2024-11-07 18:33:08

只需从请求的InputStream 加载XML,例如

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

在我看来不需要MemoryStream。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文