TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
rinku kansara
NA
5
4.9k
send sms via web application
Apr 11 2013 7:24 AM
i have code to send sms via way2sms but i cant send it.
it generate neither error nor output.
pls help me
using System;
using System.Net;
using System.IO;
using System.Text;
public partial class sms : System.Web.UI.Page
{
string ckuser, ckpass;
string id, ps, mbno, mseg;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsend_Click(object sender, EventArgs e)
{
try
{
id = txtuname.Text;
ps = txtpwd.Text;
mbno = txtmobileno.Text;
mseg = txtmessage.Text;
Session["id"] = id;
Session["pw"] = ps;
connect();
send(mbno, mseg);
}
catch (Exception ex)
{
lblError.Text = ex.Message;
lblError.Visible = true;
}
}
private void send(string mbno, string mseg)
{
if ((mbno != "") && (mseg != ""))
{
try
{
Random rand = new Random();
int rnum = rand.Next(1, 8);
string url = "http://site" + rnum + ".way2sms.com/content/index.html";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
string str = "username=" + txtuname.Text + "&password=" + txtpwd.Text;
req.ContentType = "application/x-www-form-urlencoded";
string mssg = txtmessage.Text;
string mbeno = txtmobileno.Text;
req.ContentLength = str.Length;
StreamWriter writer = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
writer.Write(str);
writer.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
res.Close();
lblError.Text = "Message Sent..... " + mbeno + ": " + mssg;
}
catch (Exception)
{
lblError.Text = "Error Sending msg....check your connection...";
}
}
else
{
lblError.Text = "Mob no or msg missing";
}
}
private void connect()
{
ckuser = Session["id"].ToString();
ckpass = Session["pw"].ToString();
try
{
Random rand = new Random();
int rnum = rand.Next(1, 8);
string url = "http://site" + rnum + ".way2sms.com/content/index.html";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
string str = "username=" + txtuname.Text + "&password=" + txtpwd.Text;
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = str.Length;
string refer = "http://site" + rnum + ".way2sms.com/";
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(res.GetResponseStream());
String resstr = reader.ReadToEnd();
Response.Write(resstr);
reader.Close();
Response.Write("Connect....");
}
catch (Exception e)
{
Response.Write("Error:" + e);
}
}
protected void btnclr_Click(object sender, EventArgs e)
{
txtuname.Text = "";
txtpwd.Text = "";
txtmobileno.Text = "";
txtmessage.Text = "";
}
}
Reply
Answers (
0
)
Is C# really become a dynamic programming language? Now
cannot use ShowDialog()