Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
I used below coding to send sms from asp.net using way2sms but i am unable to send and i am getting error like "Error Sending msg....check your connection..."
i have login account in way2sms even i can able to send msg directly from way2sms website but getting failure in asp.net. please help me out
 

 

string mbno, mseg, ckuser, ckpass;
    private HttpWebRequest req;
    private CookieContainer cookieCntr;
    private string strNewValue;
    public static string responseee;
    private HttpWebResponse response; 
    
    protected void btnsend_Click(object sender, EventArgs e)
    {         
        try
        {
            Session["id"] = txtuname.Text;
            Session["pw"] = txtpwd.Text;
            mbno = txttono.Text;
            mseg = txtmsg.Text;
 
            connect();
            sendSms(mbno, mseg);
            txttono.Text = "";
            txtmsg.Text = "";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            lblError.Visible = true;
        }
    }
 
    public void connect()
    {
        ckuser = Session["id"].ToString();
        ckpass = Session["pw"].ToString();
 
        try
        {
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");
 
            this.req.CookieContainer = new CookieContainer();
            this.req.AllowAutoRedirect = false;
            this.req.Method = "POST";
            this.req.ContentType = "application/x-www-form-urlencoded";
            this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
            this.req.ContentLength = this.strNewValue.Length;
            StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
            writer.Write(this.strNewValue);
            writer.Close();
            this.response = (HttpWebResponse)this.req.GetResponse();
            this.cookieCntr = this.req.CookieContainer;
            this.response.Close();
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
            this.req.CookieContainer = this.cookieCntr;
            this.req.Method = "GET";
            this.response = (HttpWebResponse)this.req.GetResponse();
            responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
            int index = Regex.Match(responseee, "custf").Index;
            responseee = responseee.Substring(index, 0x12);
            responseee = responseee.Replace("\"", "").Replace(">", "").Trim();
            this.response.Close();            
            lblError.Text = "connected";
        }
        catch (Exception)
        {
            lblError.Text = "Error connecting to the server...";
            Session["error"] = "Error connecting to the server...";
        }
    }
 
    public void sendSms(string mbno, string mseg)
    {
        if ((mbno != "") && (mseg != ""))
        {
            try
            {
                this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//FirstServletsms?custid=");
                this.req.AllowAutoRedirect = false;
                this.req.CookieContainer = this.cookieCntr;
                this.req.Method = "POST";
                this.req.ContentType = "application/x-www-form-urlencoded";
                this.strNewValue = "custid=undefined&HiddenAction=instantsms&Action=" + responseee + "&login=&pass=&MobNo=" + this.mbno + "&textArea=" + this.mseg;
 
                string msg = this.mseg;
                string mbeno = this.mbno;
 
                this.req.ContentLength = this.strNewValue.Length;
                StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
                writer.Write(this.strNewValue);
                writer.Close();
                this.response = (HttpWebResponse)this.req.GetResponse();
 
                this.response.Close();
                lblError.Text = "Message Sent..... " + mbeno + ": " + msg;
            }
            catch (Exception)
            {
                lblError.Text = "Error Sending msg....check your connection...";
            }
        }
        else
        {
            lblError.Text = "Mob no or msg missing";
        }
    }
 
    protected void btnclr_Click(object sender, EventArgs e)
    {
        txtuname.Text = "";
        txtpwd.Text = "";
        txttono.Text = "";
        txtmsg.Text = "";
    }
Posted 4-Feb-13 18:44pm
Edited 4-Feb-13 18:59pm
v2
Comments
JemiM at 5-Feb-13 0:49am
   
did you create an account in way2sms?
Abhishek Pant at 5-Feb-13 1:00am
   
read the question above he already defined that he is having account.
Umapathi K at 5-Feb-13 0:59am
   
yes i have
Umapathi K at 5-Feb-13 1:07am
   
some forums suggesting me its only will work on dedicated server.., is this true?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

this should help you-
send sms to mobile[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<div>
    enter phone no:<asp:TextBox id="txtphn" runat="server" >
    </asp:TextBox><br />
    enter message: <asp:TextBox id="txtxmsg" runat="server" ></asp:TextBox><br />
    <asp:button id="btn" runat="server" Text="send" onclick="btn_Click" />
    </div>
 

using System.Net;
using System.IO;
 
protected void btn_Click(object sender, EventArgs e)
    {
        try
        {
 
            send("way2sms_userid", "way2sms_password", txtxmsg.Text, txtphn.Text);
            Response.Write("message send successfully......");
        }
        catch
        {
            Response.Write("Error Occured!!!");
        }
    }
    public void send(string uid, string password, string message, string no)
    {
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=way2sms");
        HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
        System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
        string responseString = respStreamReader.ReadToEnd();
        respStreamReader.Close();
        myResp.Close();
    }
  Permalink  
Comments
Umapathi K at 5-Feb-13 1:14am
   
for this should i have to register in ubaid.tk?
AdityaPratapSingh at 5-Feb-13 1:15am
   
no it is free of cast. just write these codes in vs and run it....
Umapathi K at 5-Feb-13 1:23am
   
its not working, it will work only on dedicated server?
AdityaPratapSingh at 5-Feb-13 1:41am
   
what error msg u r getting?
Umapathi K at 5-Feb-13 5:57am
   
i am not getting any error at the same time message not delivering to which mobile number i preferred
AdityaPratapSingh at 5-Feb-13 6:01am
   
check your firewall setting. if on then off it for some time and check for any other antivirus services like trend micro scan close it. then try again. i hope it will run....
Avik Ghosh22 at 7-Feb-13 7:50am
   
not working ....
AdityaPratapSingh at 7-Feb-13 11:35am
   
check your firewall setting. if on then off it for some time and check for any other antivirus services like trend micro scan close it. then try again. i hope it will run....
Avik Ghosh22 at 8-Feb-13 0:29am
   
i have no antivirus and my computer's firewall always turn off....
RAJESHPOLAKI at 10-Feb-13 5:51am
   
is the code working
Member 9915493 at 19-Mar-13 5:32am
   
i am getting error at result status -11. Plz give me a solution Thanx in advance.
AdityaPratapSingh at 19-Mar-13 5:39am
   
'result status -11 ' what is this ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 910
1 OriginalGriff 508
2 thatraja 225
3 Abhinav S 218
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid