我们用于短信发送
这里因为我们要调用秒滴的接口,所以我们得用using System.Net.Http;这个空间
我们模仿浏览器访问: HttpClient hc = new HttpClient();
ttpResponseMessage hrm = hc.PostAsync(“网页链接”,“网页参数”);
由于我们妙滴那里需要一个md5的加密
Md5:
Md5:加密是不可以逆向解密的
//把字符串转换成字节数组
byte[] jmq = System.Text.Encoding.Default.GetBytes(str);
MD5 md = new MD5CryptoServiceProvider();
//通过字符串组转成加密后的字符串组
byte[] jfjmh = md.ComputeHash(jmq);
//得到加密后的字符串 并用空格替换掉我们的-
string strjmh = BitConverter.ToString(jfjmh).Replace("-", "");
return strjmh;
这里我们的一个发送的实例:
HttpClient hc = new HttpClient();
//获取当前时间
string time = DateTime.Now.ToString("yyyyMMddHHmmss");
string url = @"https://api.miaodiyun.com/20150822/industrySMS/sendSMS";
List<KeyValuePair<string, string>> keylist = new List<KeyValuePair<string, string>>();
keylist.Add(new KeyValuePair<string, string>("accountSid", "9bb5352e87fc412aad2f3ae9cc5d8644"));
keylist.Add(new KeyValuePair<string, string>("smsContent", "【星语】尊敬的用户,您的验证码为110"));
keylist.Add(new KeyValuePair<string, string>("timestamp", time));
keylist.Add(new KeyValuePair<string, string>("sig", md5("9bb5352e87fc412aad2f3ae9cc5d86445797ac9b01e14f7fa25ec19c1b917ee7" + time).ToLower()));
keylist.Add(new KeyValuePair<string, string>("to", username));
// keylist.Add(new KeyValuePair<string,string>("templateid", "89405961"));
// keylist.Add(new KeyValuePair<string,string>("smsContent", "[秒嘀科技]我和你和他"));
//keylist.Add(new KeyValuePair<string,string>("param", "1541,30"));
//我们的参数
HttpContent hcont = new FormUrlEncodedContent(keylist);
//这里我们等待了 用了异步 我们的方法就必须要用async
HttpResponseMessage hrm = await hc.PostAsync(url,hcont);
string reslut = await hrm.Content.ReadAsStringAsync();