c# - 将 XML 发布到 URL

标签 c# .net xml

我正在尝试将 XMLDocument 发布到 URL。这是我目前所拥有的:

   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();

我想弄清楚的是如何将此 XmlDocument 加载到 WebRequest 对象,以便它可以发布到该 URL。

最佳答案

在像这样调用 req.GetResponse() 之前,您需要写入 RequestStream。

    using (var writer = new StreamWriter(req.GetRequestStream()))
    {
        writer.Write(xml);
    }

关于c# - 将 XML 发布到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15078875/

相关文章:

.net - FormView.FindControl() 在 DataBind() 之前返回 null

c# - 如何查找计算机正在消耗的能量?

c# - 将 powershell 脚本嵌入到 c# 程序中

java - Woodstox 通过 SimpleXML 属性限制 - 如何设置它们?

c# - 为什么 IDictionary<TKey,TValue> 不/不能实现 ILookup<TKey,TValue>?

c# - 在公共(public) API 中使用可空类型

Java XSL/XML JAXB

java - 未知的 UTF-8 代码单元关闭双引号

c# - 在 64 位 Linux 环境中使用嵌入式 firebird 获取 Mono

c# - 将数据集导出到 excel 2007 EPPlus