using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Net; namespace ThreadTestSMGW { public class TornadoSMSHandler { //URL读取配置文件 public static string SITEURL = System.Configuration.ConfigurationManager.AppSettings["URL"]; public string SendSMS(string un, string pw, string da, string hex) { string time = System.DateTime.Now.ToString(); string other = "&dc=15&rd=1"; string requestUrl = SITEURL + "?un=" + un + "&pw=" + pw + "&da=" + da + "&sm=" + hex + other; //请求地址 StreamReader reader; //实现一个 TextReader(表示可读取连续字符系列的读取器。),使其以一种特定的编码从字节流中读取字符。 Uri requestUri = new Uri(requestUrl); //Uri 类,提供统一资源标识符 (URI) 的对象表示形式和对 URI 各部分的轻松访问。 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri); //提供 WebRequest 类的 HTTP 特定的实现。 request.Method = "Get"; request.ContentType = "application/x-www-form-urlencoded"; request.KeepAlive = true; request.Timeout = 1000000; WebResponse response = (HttpWebResponse)request.GetResponse(); reader = new StreamReader(response.GetResponseStream()); StringBuilder builder = new StringBuilder(); char[] buffer = new char[0x400]; int charCount = 0; while ((charCount = reader.Read(buffer, 0, buffer.Length)) > 0) { builder.Append(buffer, 0, charCount); } reader.Close(); return builder.ToString(); } } }