Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,160,372 members, 7,843,089 topics. Date: Tuesday, 28 May 2024 at 06:17 PM

Sending Sms Using Asp.net (c#) Through Http - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Sending Sms Using Asp.net (c#) Through Http (3370 Views)

Sending Sms Using Vb.net Window Application / How To Send SMS Using Asp.net/vb.net / Fellow Nairalanders Can Anyone Please Help Me With Any Software For Sending Sms (2) (3) (4)

(1) (Reply) (Go Down)

Sending Sms Using Asp.net (c#) Through Http by hsmith467330s: 2:51pm On Oct 29, 2012
Hi all,

I found this source code at http://www.ozekisms.com and I am wondering whether this code might really work of I want to send an SMS message to the given phone number with the given content.

The source code of the example application is structured in the following way:

smssend.aspx:
In this file there are page builder asp elements (text boxes, labels, etc.).

smssend.aspx.cs:
Page_Load(...): does some basic settings.
buttonSendOnClick(...): creates and sends the sms from the given data.

Description of the process depicted in Figure 1 above:

Step 1: Create the HTML form
In the smssend.aspx file, you create the form that requests the sms data. The Internet user fills in the necessaries. Label and textbox pairs will be displayed. Labels identify the requested data for the Internet user, and they will type it in textboxes. The user will be asked to fill in the Recipient and Message text fields. A multiline textbox is used to inform the Internet user about error(s) or result(s) of sending the message. At first, the error box will be invisible (it will be set in the smssend.aspx.cs file).

smssend.aspx...
<form id="smsdata" runat="server">
<asp:Table id="smstable" runat="server" style="text-align:left; border-width:thin;
border-color:Silver;" BorderStyle="Solid">
<asp:TableRow>
<asp:TableCell ColumnSpan="2">
<b>Compose a message:</b>
<br />
<br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left" VerticalAlign="Top">
<asp:Label ID="labelRecipient" runat="server" Text="Recipient: ">
</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="textboxRecipient" runat="server">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left" VerticalAlign="Top">
<asp:Label ID="labelMessage" runat="server" Text="Message Text: ">
</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="textboxMessage" runat="server" TextMode="MultiLine">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Button ID="buttonSend" runat="server" Text="Send Message"
OnClick="buttonSendOnClick" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:TextBox ID="textboxError" runat="server" BorderStyle="None"
TextMode="MultiLine"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
...




In the "protected void Page_Load(object sender, EventArgs e)" procedure (in smssend.aspx.cs), you set the width of textboxes and the error box height in rows. The text of the error box is red, and the first is invisible and empty. If using the net browser the page is downloaded for the first time, fill in the recipient and message boxes with predefined texts.

smssend.aspx.cs...
protected void Page_Load(object sender, EventArgs e)
{
textboxRecipient.Width = 400;
textboxMessage.Width = 450;
textboxMessage.Rows = 10;
textboxError.Width = 400;
textboxError.Rows = 5;

textboxError.ForeColor = System.Drawing.Color.Red;
textboxError.Visible = false;
textboxError.Text = "";

if (!Page.IsPostBack)
{
textboxRecipient.Text = "+441234567";
textboxMessage.Text = "Hello World!";
}
}
...



Step 2: Processing data coming from the HTML form
After filling in the fields and clicking the Send button , the ASP server receives the information about the form. In the smssend.aspx.cs file, the "protected void buttonSendOnClick(object sender, EventArgs e)" procedure is called. At the beginning of the procedure, check the data of the textbox fields. The Recipient box is mandatory. If it is empty, the processing will be aborted, and the Internet user will be shown the error. If the checking is successful, you will create the URL that will tell the Ozeki NG - SMS Gateway Server the requested information. We need the following: the URL of the computer running Ozeki NG - SMS Gateway Server the default URL is http://127.0.0.1/httpapi (127.0.0.1 means that Ozeki NG - SMS Gateway Server is installed on the same computer on which the ASP.NET script is running), the port number on which the server listens, the username, which is authorized to log in to the Ozeki NG - SMS Gateway Server and to send messages (the default username is admin), the user's password (the default is abc123), the message type (the default is SMS:TEXT), the recipient and the message data. The following values must be URL-encoded: username, password, recipient and message data.

smssend.aspx.cs...
protected void buttonSendOnClick(object sender, EventArgs e)
{
//fields are required to be filled in:
if (textboxRecipient.Text == ""wink
{
textboxError.Text += "Recipient(s) field must not be empty!\n";
textboxError.Visible = true;
return;
}

//we are creating the necessary URL string:
string ozSURL = "http://127.0.0.1"; //where Ozeki NG SMS Gateway is running
string ozSPort = "9501"; //port number where Ozeki NG SMS Gateway is listening
string ozUser = HttpUtility.UrlEncode("admin"wink; //username for successful login
string ozPassw = HttpUtility.UrlEncode("abc123"wink; //user's password
string ozMessageType = "SMS:TEXT"; //type of message
string ozRecipients = HttpUtility.UrlEncode(textboxRecipient.Text); //who
will get the message
string ozMessageData = HttpUtility.UrlEncode(textboxMessage.Text); //body
of message

string createdURL = ozSURL + ":" + ozSPort + "/httpapi" +
"?action=sendMessage" +
"&username=" + ozUser +
"&password=" + ozPassw +
"&messageType=" + ozMessageType +
"&recipient=" + ozRecipients +
"&messageData=" + ozMessageData;
...
}
...



Step 3: Sending a request to the SMS Gateway and receiving the answer
In the code you send a request to the Ozeki NG - SMS Gateway Server with the data of the message. It will create an SMS and send it to the recipient (mobile user) using a GSM modem/phone (if the given data is correct) and send you the result.
You create a request to the Ozeki NG - SMS Gateway Server at the URL created above. When it is done, you will receive a response from the Ozeki NG - SMS Gateway Server. The information will be retrieved from it and shown to the Internet user. Whatever problem you have, it is because the Ozeki NG - SMS Gateway Server is not running at the moment of sending data.

smssend.aspx.cs...
protected void buttonSendOnClick(object sender, EventArgs e)
{
...
try
{
//Create the request and send data to Ozeki NG SMS Gateway Server by
HTTP connection
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(createdURL);

//Get response from Ozeki NG SMS Gateway Server and read the answer
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();

//inform the user
textboxError.Text = responseString;
textboxError.Visible = true;
}
catch (Exception)
{
//if sending request or getting response is not successful, Ozeki NG - SMS Gateway Server may not be running
textboxError.Text = "Ozeki NG SMS Gateway Server is not running!";
textboxError.Visible = true;
}
}
...
Thank you for your time and answer
H.
Re: Sending Sms Using Asp.net (c#) Through Http by wiegraf: 1:58pm On Oct 30, 2012
You're going to excuse me if I don't read through your post, my attention span won't allow it. But I'll mention it's a simple matter of the api/service which the sms provider gives you. I've used smslive247, 9ja based, and it gets the job done fairly easily. They'll give you a few trial sms's and documentation is on their site.

For your current code, just follow their instructions (assuming they provide documentation) and you should be fine

Kudos
Re: Sending Sms Using Asp.net (c#) Through Http by CubixNG: 1:07pm On Sep 30, 2018
See solutions
Re: Sending Sms Using Asp.net (c#) Through Http by talk2hb1(m): 8:13pm On Sep 30, 2018
Re: Sending Sms Using Asp.net (c#) Through Http by javaMan2346: 8:21pm On Sep 30, 2018
hsmith467330s:
Hi all,

I found this source code at http://www.ozekisms.com and I am wondering whether this code might really work of I want to send an SMS message to the given phone number with the given content.

The source code of the example application is structured in the following way:

smssend.aspx:
In this file there are page builder asp elements (text boxes, labels, etc.).

smssend.aspx.cs:
Page_Load(...): does some basic settings.
buttonSendOnClick(...): creates and sends the sms from the given data.

Description of the process depicted in Figure 1 above:

Step 1: Create the HTML form
In the smssend.aspx file, you create the form that requests the sms data. The Internet user fills in the necessaries. Label and textbox pairs will be displayed. Labels identify the requested data for the Internet user, and they will type it in textboxes. The user will be asked to fill in the Recipient and Message text fields. A multiline textbox is used to inform the Internet user about error(s) or result(s) of sending the message. At first, the error box will be invisible (it will be set in the smssend.aspx.cs file).

smssend.aspx...
<form id="smsdata" runat="server">
<asp:Table id="smstable" runat="server" style="text-align:left; border-width:thin;
border-color:Silver;" BorderStyle="Solid">
<asp:TableRow>
<asp:TableCell ColumnSpan="2">
<b>Compose a message:</b>
<br />
<br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left" VerticalAlign="Top">
<asp:Label ID="labelRecipient" runat="server" Text="Recipient: ">
</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="textboxRecipient" runat="server">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left" VerticalAlign="Top">
<asp:Label ID="labelMessage" runat="server" Text="Message Text: ">
</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="textboxMessage" runat="server" TextMode="MultiLine">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Button ID="buttonSend" runat="server" Text="Send Message"
OnClick="buttonSendOnClick" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:TextBox ID="textboxError" runat="server" BorderStyle="None"
TextMode="MultiLine"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
...




In the "protected void Page_Load(object sender, EventArgs e)" procedure (in smssend.aspx.cs), you set the width of textboxes and the error box height in rows. The text of the error box is red, and the first is invisible and empty. If using the net browser the page is downloaded for the first time, fill in the recipient and message boxes with predefined texts.

smssend.aspx.cs...
protected void Page_Load(object sender, EventArgs e)
{
textboxRecipient.Width = 400;
textboxMessage.Width = 450;
textboxMessage.Rows = 10;
textboxError.Width = 400;
textboxError.Rows = 5;

textboxError.ForeColor = System.Drawing.Color.Red;
textboxError.Visible = false;
textboxError.Text = "";

if (!Page.IsPostBack)
{
textboxRecipient.Text = "+441234567";
textboxMessage.Text = "Hello World!";
}
}
...



Step 2: Processing data coming from the HTML form
After filling in the fields and clicking the Send button , the ASP server receives the information about the form. In the smssend.aspx.cs file, the "protected void buttonSendOnClick(object sender, EventArgs e)" procedure is called. At the beginning of the procedure, check the data of the textbox fields. The Recipient box is mandatory. If it is empty, the processing will be aborted, and the Internet user will be shown the error. If the checking is successful, you will create the URL that will tell the Ozeki NG - SMS Gateway Server the requested information. We need the following: the URL of the computer running Ozeki NG - SMS Gateway Server the default URL is http://127.0.0.1/httpapi (127.0.0.1 means that Ozeki NG - SMS Gateway Server is installed on the same computer on which the ASP.NET script is running), the port number on which the server listens, the username, which is authorized to log in to the Ozeki NG - SMS Gateway Server and to send messages (the default username is admin), the user's password (the default is abc123), the message type (the default is SMS:TEXT), the recipient and the message data. The following values must be URL-encoded: username, password, recipient and message data.

smssend.aspx.cs...
protected void buttonSendOnClick(object sender, EventArgs e)
{
//fields are required to be filled in:
if (textboxRecipient.Text == ""wink
{
textboxError.Text += "Recipient(s) field must not be empty!\n";
textboxError.Visible = true;
return;
}

//we are creating the necessary URL string:
string ozSURL = "http://127.0.0.1"; //where Ozeki NG SMS Gateway is running
string ozSPort = "9501"; //port number where Ozeki NG SMS Gateway is listening
string ozUser = HttpUtility.UrlEncode("admin"wink; //username for successful login
string ozPassw = HttpUtility.UrlEncode("abc123"wink; //user's password
string ozMessageType = "SMS:TEXT"; //type of message
string ozRecipients = HttpUtility.UrlEncode(textboxRecipient.Text); //who
will get the message
string ozMessageData = HttpUtility.UrlEncode(textboxMessage.Text); //body
of message

string createdURL = ozSURL + ":" + ozSPort + "/httpapi" +
"?action=sendMessage" +
"&username=" + ozUser +
"&password=" + ozPassw +
"&messageType=" + ozMessageType +
"&recipient=" + ozRecipients +
"&messageData=" + ozMessageData;
...
}
...



Step 3: Sending a request to the SMS Gateway and receiving the answer
In the code you send a request to the Ozeki NG - SMS Gateway Server with the data of the message. It will create an SMS and send it to the recipient (mobile user) using a GSM modem/phone (if the given data is correct) and send you the result.
You create a request to the Ozeki NG - SMS Gateway Server at the URL created above. When it is done, you will receive a response from the Ozeki NG - SMS Gateway Server. The information will be retrieved from it and shown to the Internet user. Whatever problem you have, it is because the Ozeki NG - SMS Gateway Server is not running at the moment of sending data.

smssend.aspx.cs...
protected void buttonSendOnClick(object sender, EventArgs e)
{
...
try
{
//Create the request and send data to Ozeki NG SMS Gateway Server by
HTTP connection
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(createdURL);

//Get response from Ozeki NG SMS Gateway Server and read the answer
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();

//inform the user
textboxError.Text = responseString;
textboxError.Visible = true;
}
catch (Exception)
{
//if sending request or getting response is not successful, Ozeki NG - SMS Gateway Server may not be running
textboxError.Text = "Ozeki NG SMS Gateway Server is not running!";
textboxError.Visible = true;
}
}
...
Thank you for your time and answer
H.

You could do all this process with not too long lines of code with java. Should I tell you how to do it in java? Or you are only interested in c# which is not secured as java?

(1) (Reply)

Biometric Data Capture Application / Why Is Python Programming So Hard To Understand / Home Page Logout On Page Refresh

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 56
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.