zoukankan      html  css  js  c++  java
  • C#发送和接受POST请求

    1、发送Post请求代码

         /// <summary>
            /// 发起Http请求
            /// </summary>
            /// <param name="flightData">发送航班对象</param>
            public static void HttpRequest(string url, string para)
            {
                byte[] bs = Encoding.UTF8.GetBytes(para);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = bs.Length;
    
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(bs, 0, bs.Length);
                }
    
                string strResponse = string.Empty;
                using (WebResponse wr = req.GetResponse())
                {
                    StreamReader responseStream = new StreamReader(wr.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                    strResponse = responseStream.ReadLine();
                }
            }

    2、接受Post请求

           if (!string.IsNullOrEmpty(this.Request.Form.ToString()))
                {
                    string str = HttpUtility.UrlDecode(this.Request.Form.ToString(), Encoding.UTF8);
                }
    作者:BestNow
    出处:http://www.cnblogs.com/BestNow/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    jQuery之五:CheckBox控制
    WinServer2003 设置之:xp风格
    ASP.net: cookie
    ASP.NET之:URL重写(转载)
    jQuery 之二:Ajax加载Json数据
    jQuery 之一:对象插件
    Asp.net:Form
    jQuery之四:Table过滤
    jQuery之三:Tab控制
    Opera 9.01 Build 8543
  • 原文地址:https://www.cnblogs.com/tianxue/p/3979691.html
Copyright © 2011-2022 走看看