发送短信验证码

System.Text.StringBuilder sbTemp = new System.Text.StringBuilder();
sbTemp.Append("apikey=&username=&password=**&mobile=手机号&content=您本次短信验证码是:" + message);
byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
string result = Common.Post("http://m.5c.com.cn/api/send/?", bTemp);

public static string Post(string url, byte[] data)
{
string result = "";
try
{

            System.Net.HttpWebRequest request = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;
            request.AllowAutoRedirect = true;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            Stream outstream = request.GetRequestStream();
            outstream.Write(data, 0, data.Length);
            outstream.Close();
            System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse;
            Stream instream = response.GetResponseStream();
            using (StreamReader reader = new StreamReader(instream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
        }
        catch { }
        return result;

}

posted @ 2021-07-09 14:11  cv玲玲  阅读(218)  评论(0编辑  收藏  举报