首页 > Windows开发 > 详细

C# 后台POST请求(winform)

时间:2014-06-12 14:50:55      阅读:681      评论:0      收藏:0      [点我收藏+]

     //data:参数  URL:路径

  public static string PostWebRequest(string Data, string URL)
        {
            CookieContainer cc = new CookieContainer();
            string postData = Data;
            byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
            HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri(URL));
            webRequest2.CookieContainer = cc;
            webRequest2.Method = "POST";
            webRequest2.ContentType = "application/x-www-form-urlencoded";
            webRequest2.ContentLength = byteArray.Length;
            Stream newStream = webRequest2.GetRequestStream();
            newStream.Write(byteArray, 0, byteArray.Length);    //写入参数
            newStream.Close();
            HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
            StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.UTF8);
            string text2 = sr2.ReadToEnd();
            if (text2 != null && text2.Length > 0)
            {
                return text2;
            }
            return "";
        }

C# 后台POST请求(winform),布布扣,bubuko.com

C# 后台POST请求(winform)

原文:http://www.cnblogs.com/ellanjianx/p/3782034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!