zoukankan      html  css  js  c++  java
  • ASP.NET中将数据作为XML数据发送 使用 Request.InputStream 接收

    将数据作为XML数据发送,例如:
    public void PostXml(string url, string xml)
    {
    byte[] bytes = Encoding.UTF8.GetBytes(xml);
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
    request.Method = "POST";
    request.ContentLength = bytes.Length;
    request.ContentType = "text/xml";
    using (Stream requestStream = request.GetRequestStream()) {
    requestStream.Write(bytes, 0, bytes.Length);
    }HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    if (response.StatusCode != HttpStatusCode.OK) {
    string message = String.Format("POST failed. Received HTTP {0}",
    response.StatusCode);
    throw new ApplicationException(message);
    }
    }
    接收端通过Request.InputStream读取:
    byte[] byts = new byte[Request.InputStream.Length];
    Request.InputStream.Read(byts,0,byts.Length);
    string req = System.Text.Encoding.Default.GetString(byts);
    req = Server.UrlDecode(req);
    对于完整的XML数据,可以:
    xmlDoc = new XmlDocument();
    xmlDoc.load(Request.InputStream);

  • 相关阅读:
    JavaScript中弧度和角度的转换
    HTML <meta> Attribute
    rel 属性<small>H5保留属性</small>
    React学习笔记
    React学习笔记
    jQuery插件制作
    jQuery ajax
    js数据存贮之数组与json
    列表与表格的一些学习
    18-10-16学习内容总结
  • 原文地址:https://www.cnblogs.com/mili3/p/3964087.html
Copyright © 2011-2022 走看看