Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. [WebMethod]
  2. public string SendSMS_NEW(string ChannelID,string LinkID,string Data)
  3. {
  4. String retxmlData="";
  5. try
  6. {
  7. if (Data.IndexOf("news_id:") >= 0)
  8. {
  9. long news_id = Convert.ToInt64(Data.Substring(8));
  10. Data = get_news_from_db(news_id);
  11. }
  12.  
  13. HttpWebRequest req = null;
  14. HttpWebResponse rsp = null;
  15.  
  16. //http://sdpcontentapi.mobi-mind.net/Content.asmx/UploadNormalText?User=test&Password=test&LinkID=123&ChannelID=123&Data=test%20data
  17.  
  18. string uri = "http://sdpcontentapi.mobi-mind.net/Content.asmx";
  19. string action = "http://sdpcontentapi.mobi-mind.net/Content.asmx?op=UploadNormalText";
  20. req = (HttpWebRequest)WebRequest.Create(uri);
  21. req.Headers.Add("SOAPAction", action);
  22. req.Method = "POST"; // Post method
  23. req.ContentType = "text/xml; charset=utf-8";
  24. //req.ContentLength = "";
  25.  
  26. //req.Accept = "application/soap+xml, application/dime, multipart/related, text/*";
  27. //req.UserAgent = "Axis/1.4";
  28.  
  29. StreamWriter writer = new StreamWriter(req.GetRequestStream(), Encoding.UTF8);
  30. writer.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
  31. writer.Write("<soapenv:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>");
  32. writer.Write("<soapenv:Header/>");
  33. writer.Write("<soapenv:Body>");
  34. writer.Write("<UploadNormalText xmlns=\"http://tempuri.org/\">");
  35. writer.Write("<User>FF27A4D413DA4EFF8F2EC3AF7482229F</User>");
  36. writer.Write("<Password>7rzI42Ga</Password>");
  37. writer.Write("<LinkID>" + LinkID + "</LinkID>");
  38. writer.Write("<ChannelID>" + ChannelID + "</ChannelID>");
  39. writer.Write("<Data>" + Data + "</Data>");
  40. writer.Write(" </UploadNormalText>");
  41. writer.Write("</soapenv:Body>");
  42. writer.Write("</soapenv:Envelope>");
  43.  
  44. writer.Close();
  45.  
  46. rsp = (HttpWebResponse)req.GetResponse();
  47.  
  48. System.IO.StreamReader reader = new System.IO.StreamReader(rsp.GetResponseStream());
  49. retxmlData = reader.ReadToEnd();
  50. //MessageBox.Show(retxmlData);
  51. if (req != null) req.GetRequestStream().Close();
  52. if (rsp != null) rsp.GetResponseStream().Close();
  53.  
  54. }
  55. catch (System.Net.WebException ex)
  56. {
  57. String responseFromServer = ex.Message.ToString() + " ";
  58. if (ex.Response != null)
  59. {
  60. using (WebResponse response = ex.Response)
  61. {
  62. Stream data = response.GetResponseStream();
  63. using (StreamReader reader = new StreamReader(data))
  64. {
  65. responseFromServer += reader.ReadToEnd();
  66. }
  67. }
  68. }
  69.  
  70. }
  71. return retxmlData;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement