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