Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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




C#
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
Updated 4-Feb-13 18:59pm
v2
Comments
Jameel VM 5-Feb-13 0:49am    
did you create an account in way2sms?
Abhishek Pant 5-Feb-13 1:00am    
read the question above he already defined that he is having account.
Umapathi K 5-Feb-13 0:59am    
yes i have
Umapathi K 5-Feb-13 1:07am    
some forums suggesting me its only will work on dedicated server.., is this true?

System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse()
 
Share this answer
 
Comments
Deepu S Nair 14-Apr-15 7:43am    
?
Member 12062791 19-Nov-15 1:02am    
sir i tried this code msg is error occured
next i check breakpoint never next process after this code plz help me

HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
XML
<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>



C#
using System.Net;
using System.IO;


C#
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();
    }
 
Share this answer
 
Comments
Umapathi K 5-Feb-13 1:14am    
for this should i have to register in ubaid.tk?
AdityaPratapSingh 5-Feb-13 1:15am    
no it is free of cast. just write these codes in vs and run it....
Umapathi K 5-Feb-13 1:23am    
its not working, it will work only on dedicated server?
AdityaPratapSingh 5-Feb-13 1:41am    
what error msg u r getting?
Umapathi K 5-Feb-13 5:57am    
i am not getting any error at the same time message not delivering to which mobile number i preferred
this should help you-
send sms to mobile[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900