加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 将XML发布到URL

发布时间:2020-12-15 06:51:28 所属栏目:百科 来源:网络整理
导读:我试图将一个 XMLDocument发布到一个URL.这是我到目前为止 var uri = System.Configuration.ConfigurationManager.AppSettings["Url"]; var template = System.Configuration.ConfigurationManager.AppSettings["Template"]; XmlDocument reqTemplateXml = n
我试图将一个 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);
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读