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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    创建被访问的swf文件
    BFS寻路算法的实现
    Flex里的命名空间,fx、mx、s【转】
    Flex的基础用法【转】
    Pow(x, n)
    Roman to Integer
    Integer to Roman
    Divide Two Integers
    Single Number II
    Single Number I
  • 原文地址:https://www.cnblogs.com/tianxue/p/3979691.html
Copyright © 2011-2022 走看看