.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets


Posted By:Athira Sreejith       Posted Date: February 05, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

using System.IO;
using System.Threading;
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page

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!";

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


string url = "http://soft.net";

string url1 = String.Format(url, textboxRecipient.Text, textboxMessage.Text);

//create Web Request object for the url
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url1);

// get the response from the web request
HttpWebResponse res = (HttpWebResponse)req.GetResponse();

// read the response from the WebResponse in to a stram
Stream s = res.GetResponseStream();
StreamReader rdr = new StreamReader(s);
string result = rdr.ReadLine();

catch (Exception)
//if sending request or getting response is not successful Ozeki NG SMS Gateway Server may do not run
textboxError.Text = "Ozeki NG SMS Gateway Server is not running!";
textboxError.Visible = true;


//////////////////////For Ozoki
//we creating the necessary URL string:
//string ozSURL = ""; //where Ozeki NG SMS Gateway is running
//string ozSPort = "9501"; //port number where Ozeki NG SMS Gateway is listening
//string ozUser = HttpUtility.UrlEncode("admin"); //username for successful login
//string ozPassw = HttpUtility.UrlEncode("admin"); //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;

////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();

////inform the user
//textboxError.Text = responseString;
//textboxError.Visible = true;



Further Readings:


    No response found. Be the first to respond this post

    Post Comment

    You must Sign In To post reply
    Find More code samples in C#, ASP.Net, Vb.Net and more Here

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend