本帖最后由 aladin1980 于 2022-4-1 22:44 编辑
- string mobile = "18602112512",
- message = "Test send message use luosimao!【铁壳测试】",
- username = "api",
- password = "key-b2652cf62f07dd09a4d561dcb4528032",
- url = "http://sms-api.luosimao.com/v1/send.json";
- byte[] byteArray = Encoding.UTF8.GetBytes("mobile=" + mobile + "&message=" + message);
- HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
- string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(username + ":" + password));
- webRequest.Headers.Add("Authorization", auth);
- webRequest.Method = "POST";
- webRequest.ContentType = "application/x-www-form-urlencoded";
- webRequest.ContentLength = byteArray.Length;
- Stream newStream = webRequest.GetRequestStream();
- newStream.Write(byteArray, 0, byteArray.Length);
- newStream.Close();
- HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
- StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.Default);
- string Message = php.ReadToEnd();
- System.Console.Write(Message);
- System.Console.Read();
复制代码
|