public string send_sms() { string str_userid = "ID" string str_account = "账号" string str_password = "密码" string str_content = "内容" string str_mobile = "手机号码"//130xxxxxxxx,131xxxxxxxx多个号码用英文半角分隔
string param = string.Format(@"action=send&rt=json&userid={0}&account={1}&password={2}&content={3}&mobile={4}", str_userid, str_account, str_password, str_content, str_mobile); string url = "http://dc.28inter.com/sms.aspx" Response.Write(PostSend(url, param));//输出返回值 }
private string PostSend(string url, string postdate) { HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); myHttpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8" myHttpWebRequest.Method = "POST" Stream myRequestStream = myHttpWebRequest.GetRequestStream(); StreamWriter myStreamWriter = new StreamWriter(myRequestStream); myStreamWriter.Write(postdate); myStreamWriter.Flush(); myStreamWriter.Close(); myRequestStream.Close();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); Stream myResponseStream = myHttpWebResponse.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); String outdata = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return outdata; } |