云通訊平臺(tái)-C# Post.cs短信接口開發(fā)示例
using System.Configuration; |
using System.Collections; |
using System.Web.Security; |
using System.Web.UI.WebControls; |
using System.Web.UI.WebControls.WebParts; |
using System.Web.UI.HtmlControls; |
using System.Security.Cryptography.X509Certificates; |
using System.Net.Security; |
public partial class Post : System.Web.UI.Page |
public static string PostUrl = ConfigurationManager.AppSettings["WebReference.Service.PostUrl"]; |
protected void Page_Load(object sender, EventArgs e) |
protected void ButSubmit_Click(object sender, EventArgs e) |
string un = this.Txtaccount.Text.Trim(); |
string pw = this.Txtpassword.Text.Trim(); |
string phone = this.Txtmobile.Text.Trim(); |
string content = "【云通訊】" + HttpContext.Current.Server.UrlEncode(this.Txtcontent.Text.Trim()); |
string postJsonTpl = ""account":"{0}","password":"{1}","phone":"{2}","report":"false","msg":"{3}""; |
string jsonBody = string.Format(postJsonTpl, un, pw, phone, content); |
string result = doPostMethodToObj("http://xxx/msg/send/json", "{" + jsonBody + "}");//請(qǐng)求地址請(qǐng)登錄云通訊平臺(tái)查看或者詢問您的商務(wù)負(fù)責(zé)人獲取 |
LabelRetMsg.Text = result; |
public static string doPostMethodToObj(string url, string jsonBody) |
string result = String.Empty; |
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); |
httpWebRequest.ContentType = "application/json"; |
httpWebRequest.Method = "POST"; |
NetworkCredential admin_auth = new NetworkCredential("username", "password"); |
httpWebRequest.Credentials = admin_auth; |
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; |
using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) |
streamWriter.Write(jsonBody); |
HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); |
using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream())) |
result = streamReader.ReadToEnd(); |