Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string SendSMS(string _message, string _phone_number)
- {
- var enc = System.Text.Encoding.GetEncoding("EUC-JP");
- var postData = "";
- try
- {
- //POST送信する文字列を作成
- postData = postData + String.Format("username={0}&", HttpUtility.UrlEncode(_username));
- postData = postData + String.Format("password={0}&", HttpUtility.UrlEncode(_password));
- postData = postData + String.Format("trigger_id={0}&", HttpUtility.UrlEncode(_trigger_id1));
- postData = postData + String.Format("phone_number={0}&", HttpUtility.UrlEncode(_PhoneNumber));
- postData = postData + String.Format("message={0}&", HttpUtility.UrlEncode(_message));
- //バイト型配列に交換
- var postDataBytes = System.Text.Encoding.ASCII.GetBytes(postData);
- //WebRequestの作成
- System.Net.WebRequest req = System.Net.WebRequest.Create(_SMSURL);
- req.Timeout = System.Threading.Timeout.Infinite;
- //メソッドにPOSTを指定
- req.Method = "POST";
- //ContentTypeを"application/x-www-form-urlencoded"にする
- req.ContentType = "application/x-www-form-urlencoded";
- //POST送信するデータの長さを指定
- req.ContentLength = postDataBytes.Length;
- //データをPOST送信するためのStreamを取得
- System.IO.Stream reqStream = req.GetRequestStream();
- //送信するデータを書き込む
- reqStream.Write(postDataBytes, 0, postDataBytes.Length);
- reqStream.Close();
- //サーバーからの応答を受信するためのWebResponseを取得
- var res = req.GetResponse();
- //応答データを受信するためのStreamを取得
- var resStream = res.GetResponseStream();
- //XML形式へ
- var objXMLReader = new XmlTextReader(resStream);
- var xmldoc = new XmlDocument();
- xmldoc.Load(objXMLReader);
- objXMLReader.Close();
- }
- catch(Exception e)
- {
- return " Send SMS Error " + e.Message + " log:" + _log;
- }
- }
- ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement