创蓝语音服务(语音通知验证码).net

时间:2021-05-13 08:47:06
  public static string PostUrl = "http://zapi.253.com/msg/HttpBatchSendSM";
static void Main(string[] args)
{
string account = "";
string password = "";
string mobile = "";
string content = "您的登陆验证码是1234"; string postStrTpl = "account={0}&pswd={1}&mobile={2}&msg={3}&needstatus=true&product=&extno="; UTF8Encoding encoding = new UTF8Encoding();
byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content)); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = postData.Length; Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(postData, , postData.Length);
newStream.Flush();
newStream.Close(); HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); if (myResponse.StatusCode == HttpStatusCode.OK)
{
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
myResponse.Close();
myRequest.Abort();
Console.WriteLine("发送成功");
Console.ReadKey();
}
else
{
myRequest.Abort();
myResponse.Close();
Console.WriteLine("发送失败");
Console.ReadKey();
}
}

创蓝语音服务.net(返回错误的情况)

  public static string PostUrl = "http://zapi.253.com/msg/HttpBatchSendSM";
static void Main(string[] args)
{
string account = "V0240532111";
string password = "pE3e8r60wM01c5111";
string mobile = "";
string content = "您的登陆验证码是1234";
string postStrTpl = "account={0}&pswd={1}&mobile={2}&msg={3}&needstatus=true&product=&extno="; UTF8Encoding encoding = new UTF8Encoding();
byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content));
string resultCode = "";
HttpWebRequest myRequest = null;
HttpWebResponse myResponse = null;
try
{
myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = postData.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(postData, , postData.Length);
newStream.Flush();
newStream.Close(); myResponse = (HttpWebResponse)myRequest.GetResponse(); if (myResponse.StatusCode == HttpStatusCode.OK)
{
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string result = reader.ReadToEnd(); if (result != null)
{
string[] arr = result.Split(',');
resultCode = arr[];
}
}
}catch(Exception ex)
{
Console.Write(ex);
}
finally
{
if (myRequest != null)
{
myRequest.Abort();
}
if (myResponse != null)
{
myResponse.Close();
}
}
if (resultCode.StartsWith(""))
{
Console.WriteLine("发送成功");
Console.ReadKey();
}
else
{
Console.WriteLine("发送失败" + resultCode);
Console.ReadKey();
}
}