Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. public string SendSMS(string _message, string _phone_number)
  2. {
  3. var enc = System.Text.Encoding.GetEncoding("EUC-JP");
  4. var postData = "";
  5.  
  6. try
  7. {
  8. //POST送信する文字列を作成
  9. postData = postData + String.Format("username={0}&", HttpUtility.UrlEncode(_username));
  10. postData = postData + String.Format("password={0}&", HttpUtility.UrlEncode(_password));
  11. postData = postData + String.Format("trigger_id={0}&", HttpUtility.UrlEncode(_trigger_id1));
  12. postData = postData + String.Format("phone_number={0}&", HttpUtility.UrlEncode(_PhoneNumber));
  13. postData = postData + String.Format("message={0}&", HttpUtility.UrlEncode(_message));
  14.  
  15. //バイト型配列に交換
  16. var postDataBytes = System.Text.Encoding.ASCII.GetBytes(postData);
  17. //WebRequestの作成
  18. System.Net.WebRequest req = System.Net.WebRequest.Create(_SMSURL);
  19.  
  20. req.Timeout = System.Threading.Timeout.Infinite;
  21.  
  22. //メソッドにPOSTを指定
  23. req.Method = "POST";
  24. //ContentTypeを"application/x-www-form-urlencoded"にする
  25. req.ContentType = "application/x-www-form-urlencoded";
  26. //POST送信するデータの長さを指定
  27. req.ContentLength = postDataBytes.Length;
  28. //データをPOST送信するためのStreamを取得
  29. System.IO.Stream reqStream = req.GetRequestStream();
  30.  
  31. //送信するデータを書き込む
  32. reqStream.Write(postDataBytes, 0, postDataBytes.Length);
  33.  
  34. reqStream.Close();
  35.  
  36. //サーバーからの応答を受信するためのWebResponseを取得
  37. var res = req.GetResponse();
  38. //応答データを受信するためのStreamを取得
  39. var resStream = res.GetResponseStream();
  40. //XML形式へ
  41. var objXMLReader = new XmlTextReader(resStream);
  42.  
  43. var xmldoc = new XmlDocument();
  44. xmldoc.Load(objXMLReader);
  45. objXMLReader.Close();
  46.  
  47.  
  48. }
  49. catch(Exception e)
  50. {
  51. return " Send SMS Error " + e.Message + " log:" + _log;
  52. }
  53. }
  54.  
  55. ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement