zoukankan      html  css  js  c++  java
  • C#中怎么将XML作为参数post到接口

    String xml = "<data>中文</data>";
    String postData = "data=" + Server.UrlEncode(xml); ;
    string strUrl = "http://localhost:29833/WebSite1/xx.aspx";      
    // 准备请求... 
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl); 
    myRequest.Method = "POST";       
    myRequest.ContentType="application/x-www-form-urlencoded";
    myRequest.ContentLength = postData.Length;
    Stream newStream=myRequest.GetRequestStream();      
    byte[] data = Encoding.GetEncoding("GB2312").GetBytes(postData);
    // 发送数据 
    newStream.Write(data,0,data.Length);
    HttpWebResponse res = myRequest.GetResponse() as HttpWebResponse;
    StreamReader sr  = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
    String ret = sr.ReadToEnd();
    newStream.Close();
    Response.Write("你提交的是:" + Server.HtmlEncode( ret));
    
    
    //==========
    接口的接收
    Response.ClearContent();
    Response.Write(Request.Form["data"]);
    Response.End();
     
     
    

      

    from:http://topic.csdn.net/u/20101117/11/bfee4a29-d966-4870-9026-0243767067a6.html

  • 相关阅读:
    js-artDialog文档说明
    T-SQL数据库函数
    强大的Jquery对象选择器
    学习正则表达式
    经典正则
    其他常用的正则表达式
    celery的使用
    django中间件
    AJAX
    Django Form表单组件
  • 原文地址:https://www.cnblogs.com/dare/p/8117617.html
Copyright © 2011-2022 走看看