private void SendMsg(string strMobile,string strMsg,string strSvid,string strCPUID,string strPWD,string strSender)//FeeType(资费类别)FeeCode(资费代码)ChargeTermID(计费号码)DestTermID(接收消息的目的号码)sReplyPath(用户回复号码)//MsgContent(短消息内容)MsgType(消息类型){ try { string postData=""; Encoding encoding = Encoding.GetEncoding("utf-8"); postData += "<linkrich-mt>"; postData += "<version>200</version>"; postData += "<customer>"+strCPUID+"</customer>"; postData += "<pwd>"+strPWD+"</pwd>"; postData += "<service>"+strSvid+"</service>"; postData += "<srcmobile>"+strMobile+"</srcmobile>"; postData += "<source>"+strSender+"</source>"; postData += "<destmobile>"+strMobile+"</destmobile>"; postData += "<type>17</type>"; postData += "<message>"+strMsg+"</message>"; postData += "<pid>0</pid>"; postData += "<udhi>0</udhi>"; postData += "<time>0</time>"; postData += "</linkrich-mt>"; string strUrl = "URL";//接口地址
byte[] data = encoding.GetBytes(postData);
// 准备请求... HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl); myRequest.Method = "POST"; myRequest.ContentType="application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; Stream newStream=myRequest.GetRequestStream(); // 发送数据 newStream.Write(data,0,data.Length);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myRequest.GetResponse(); Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader(receiveStream, encode );
strContent=readStream.ReadToEnd(); strContent=strContent.Substring((strContent.IndexOf("<status>")+8),1); StreamWriter fs=new StreamWriter("E:/HttpLog/log.txt",true,System.Text.Encoding.Default); fs.WriteLine(DateTime.Now+":"+strMobile+" "+strContent); fs.Close(); newStream.Close(); }
catch(Exception e1) { string strFileName="E:/HttpLog/errorlog.txt"; StreamWriter fs=new StreamWriter(strFileName,true,System.Text.Encoding.Default); fs.WriteLine(DateTime.Now+":"+strMobile+" "+e1.ToString()); fs.WriteLine(""); fs.Close(); }}上面是发送短信的代码接受的方法就只要用Request.QueryString[""]得到就可以了不过要根据SP提供的文档而定