empty
public string SendShortMessage(string mobile, string code)
{
string result = string.Empty;
//string SMSurl = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SMSurl"].ToString();
string SMSkey = "Sa8&Une3(us*$5s!A";
string timeNow = DateTime.Now.ToString("yyyyMMddHHmmss");
string md5key = GetMD5(SMSkey + timeNow);
//测试
//string url = "接口地址";
skyform_param_json_param skyform = new skyform_param_json_param();
skyform.Mobs = mobile;
skyform.Content = HttpUtility.UrlEncode("短信内容:" + code);
skyform.StartTime = DateTime.Now.ToString("yyyyMMddHHmmss");
skyform.EndTime = DateTime.Now.AddMinutes(15).ToString("yyyyMMddHHmmss");
string strRes = JsonConvert.SerializeObject(skyform);
//System.Text.Encoding encoding = System.Text.Encoding.UTF8;
System.Net.HttpWebResponse response = null;
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
request.Method = "POST";
//request.Accept = "text/html, application/xhtml+xml, */*";
request.Accept = "application/json, text/javascript, */*";
//request.ContentType = "application/json";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Headers.Add("MLXC_AU_ENC_FLAG", md5key);
request.Headers.Add("MLXC_AU_ENC_TIME", timeNow);
request.Headers.Add("skyform_param_json_param", strRes);
request.Headers.Add("platformId", "MLXC_20161104");
request.Timeout = 300000;
//byte[] buffer = encoding.GetBytes(strPostData);
//request.ContentLength = buffer.Length;
//request.GetRequestStream().Write(buffer, 0, buffer.Length);
//request.GetRequestStream();
try
{
response = (System.Net.HttpWebResponse)request.GetResponse();
using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
{
result = reader.ReadToEnd();
reader.Close();
response.Close();
//result=AddSendMessageLog(result);
}
}
catch (Exception)
{
}
finally
{
if (response != null)
{
response.Close();
}
if (request != null)
{
request.Abort();
}
}
return result;
}
Http请求响应--发短信
最新推荐文章于 2022-04-25 14:28:14 发布