Click here to Skip to main content
12,511,920 members (42,836 online)
Rate this:
 
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
Updated 4-Feb-13 18:59pm
v2
Comments
JemiM 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?
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 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
AdityaPratapSingh 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 7-Feb-13 7:50am
   
not working ....
AdityaPratapSingh 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 8-Feb-13 0:29am
   
i have no antivirus and my computer's firewall always turn off....
RAJESHPOLAKI 10-Feb-13 5:51am
   
is the code working
Member 9915493 19-Mar-13 5:32am
   
i am getting error at result status -11.
Plz give me a solution
Thanx in advance.
AdityaPratapSingh 19-Mar-13 5:39am
   
'result status -11 ' what is this
?
Member 11894006 27-Oct-15 5:47am
   
i am getting error which is 404 may be port no says that not found.
Member 12062791 19-Nov-15 1:20am
   
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();
Member 12062791 19-Nov-15 1:44am
   
sir i code in asp.net sms sending using vianettsms code is successfully result is message sent successfully but msg never send the mobils





protected void Button1_Click(object sender, EventArgs e)
{

try
{

send("xxxxxx", "yyyyy", 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://smsc.vianett.no/ActiveServer/MT/?" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=vianettsms");
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
}
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse()
  Permalink  
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();

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 14 Apr 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100