zoukankan      html  css  js  c++  java
  • ASP.NET POST XML JSON数据,发送与接收

    接收端通过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);

    将数据作为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);
       }
    }

  • 相关阅读:
    自定义组件
    vue 父子组件传值数据不能实时更新问题
    vuex(2)
    vuex(1)
    mysql-忘记密码
    转发&重定向
    mysql主从配置
    mysql安装脚本
    1、JAVA数据类型
    maven 国内阿里云镜像配置
  • 原文地址:https://www.cnblogs.com/flysnow-z/p/4679410.html
Copyright © 2011-2022 走看看