در این مثال فرض شده است که ادرس اینترنتی سرویس پرهات http://ws.rahatsms.com/webservices/wsurl/url/send
باشد.
private string
SendSMS()
{
string URL =
"http://ws.rahatsms.com/webservices/wsurl/url/send";
string Username =
"YOUR-USERNAME";
string Password =
"YOUR-PASSWORD";
int RequestTimeout = 30000;
string Text =
"YOUR-TEXT";
string Recipient =
"RECIPIENT(s)";
string Channel =
"YOUR-CHANNEL";
string parameters =
string.Format(
"UserName={0}&Password={1}&Text={2}&To={3}&From={4}",Username,Password,Text,Recipient,Channel);
try
{
URL = String.Concat(URL.ToString(), "?", parameters.ToString());
System.Net.WebProxy proxyObject = new
System.Net.WebProxy();
System.Net.WebRequest request = System.Net.WebRequest.Create(URL);
request.Timeout = (int)RequestTimeout;
request.Proxy = proxyObject;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
System.IO.StreamWriter sw = new
System.IO.StreamWriter(request.GetRequestStream());
sw.Write(request);
sw.Close();
System.Net.WebResponse objResponse = request.GetResponse();
System.IO.StreamReader sr = new
System.IO.StreamReader(objResponse.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
return result;
}
catch (Exception ex)
{
return ex.Message;
}
}