zoukankan      html  css  js  c++  java
  • Winform C#关于utf8编码问题

     public string SendDataByPost(string param, string Url)
            {
                try
                {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                    byte[] bs = Encoding.UTF8.GetBytes(param);
                    request.Method = "Post";
                    request.ContentType = "application/x-www-form-urlencoded;charset=utf8";
                    request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0";
                    request.Accept = "application/json, text/javascript, */*; q=0.01";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = bs.Length;
                    Stream newSteam = request.GetRequestStream();
                    newSteam.Write(bs, 0, bs.Length);
                    newSteam.Close();
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream myResponseStream = response.GetResponseStream();
                    StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
                    string retString = myStreamReader.ReadToEnd();
                    myStreamReader.Close();
                    myResponseStream.Close();
    
                    return retString;
                }
                catch (Exception ex)
                {
                    return ex.ToString();
                }
    
            }
    

      

            public string MD5(string str)
            {
                //微软md5方法参考return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "md5");
                byte[] b = Encoding.UTF8.GetBytes(str);
                b = new MD5CryptoServiceProvider().ComputeHash(b);
                string ret = "";
                for (int i = 0; i < b.Length; i++)
                    ret += b[i].ToString("x").PadLeft(2, '0');
                return ret;
            }
  • 相关阅读:
    MyBatis缓存
    MyBatis动态SQL
    MyBatis中#{}和${}的区别
    MyBatis映射配置文件详解
    MyBatis核心配置文件详解
    MyBatis动态代理
    KO ------- 表中字段名和实体类属性名不一致
    对实体类的CRUD操作
    MyBatis配置数据源的两种方式
    MyBatis入门
  • 原文地址:https://www.cnblogs.com/wangzhenghua/p/11685772.html
Copyright © 2011-2022 走看看