I want to send sms through ASP.Net appliation

Posted by Shanthosh2110 under ASP.NET on 1/11/2012 | Points: 10 | Views : 1089 | Status : [Member] | Replies : 1
Hi,

I want to send sms through ASP.Net or through C# apllication. Can anyone please help me.

Thanks in Advance.

shanthosh.s


Responses

Posted by: Nsatija on: 1/14/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.sendandreceivesms.com/be/post/2011/12/12/How-to-send-sms-in-c-sharp.aspx

using System.Net;

using System.IO;

partial class demo : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
SendSMS("18479790553", "ToNumber", "test");
}

public void SendSMS(string FromNumber, string ToNumber, string SMS)
{

string url = "http://www.sendandreceivesms.com/api/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
string postData = "FromNumber=" + FromNumber;
postData += "&";
postData += "ToNumber=" + ToNumber;
postData += "&";
postData += "SMS=" + SMS;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.Headers.Add("APIToken", "GET API TOKEN BY REGISTERING");
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
if ((string.IsNullOrEmpty(responseFromServer))) {
//Label1.Text += "Nothing returned"
} else {
//Label1.Text += responseFromServer
}
reader.Close();
dataStream.Close();
response.Close();
}
}




Nick S

Shanthosh2110, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response