zoukankan      html  css  js  c++  java
  • C# 后台POST请求(winform)

         //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 "";
            }

  • 相关阅读:
    FORTRAN学习记录
    Ubuntu查看和自动挂载硬盘
    正则表达式批量重命名
    [USACO 09FEB]Fair Shuttle
    [ZJOI 2012]灾难
    [BJOI 2010]次小生成树Tree
    Python开发 第一篇 python的前世今生
    关于pycharm字体大小的调整
    关于"人工智能Python""系统环境变量设置步骤
    [洛谷P1168]中位数
  • 原文地址:https://www.cnblogs.com/ellanjianx/p/3782034.html
Copyright © 2011-2022 走看看