Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wrote the following code for sending sms from my application , when i clicked on send message, it's not sending any message to mobile......


protected void btnsubmit_Click1(object sender, EventArgs e)
   {
       string senderusername = txtsenderid.Text;
       string senderpwd = txtpwd.Text;
       string msg = txtmsg.Text;
       string phonenumber = txtnumber.Text;
       string senderid = txtsenderid.Text;
       string sURL;
       StreamReader objReader;
       sURL = "http://api.fastalerts.in/fastclient/SMSclient.php?username=" + senderusername + "&password=" + senderpwd + "&message=" + msg + "&numbers=" + phonenumber + "&senderid=" + senderid;
 System.Net.WebRequest wrGETURL;
       wrGETURL = System.Net.WebRequest.Create(sURL);
       try
       {
           Stream objStream;
           objStream = wrGETURL.GetResponse().GetResponseStream();
           objReader = new StreamReader(objStream);
           objReader.Close();
       }
       catch (Exception ex)
       {
           ex.ToString();
       }
   }
Posted
Comments
saud_a_k 7-Nov-12 4:01am    
I think you need to use a webservice like

http://www.webservicex.net/sendsms.asmx
bbirajdar 7-Nov-12 4:18am    
What is the response message you get for this HTTP post ?
Sumit_Kumar_Sinha 7-Nov-12 4:28am    
nothing
bbirajdar 7-Nov-12 7:48am    
You are missing this code

webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.Timeout = 5000;

webRequest.ContentLength = bytes.Length;

Hi,

I have never tried this earlier.
Got this link on googling.

http://www.c4sms.com/codeExamples.asp[^]

Hope this can be of some help.
 
Share this answer
 
Use this code

C#
HttpWebRequest webRequest = null;
string response = "";
byte[] bytes = Encoding.UTF8.GetBytes(xml);

try
{
    webRequest = (HttpWebRequest)WebRequest.Create("http://api.fastalerts.in/fastclient/SMSclient.php?username=" + senderusername + "&password=" + senderpwd + "&message=" + msg + "&numbers=" + phonenumber + "&senderid=" + senderid;);
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.Method = "POST";
    webRequest.Timeout = 5000;

    webRequest.ContentLength = bytes.Length;
    using (Stream requeststream = webRequest.GetRequestStream())
    {
        requeststream.Write(bytes, 0, bytes.Length);
        requeststream.Close();
    }

    using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
    {
        using (StreamReader sr = new StreamReader(webResponse.GetResponseStream()))
        {
            response = sr.ReadToEnd().Trim();
            sr.Close();
        }
        webResponse.Close();
    }
}
catch(Exception ex)
{
    
}
return response;
 
Share this answer
 
Comments
Sumit_Kumar_Sinha 9-Nov-12 1:57am    
It's throwing some error like :-

Compiler Error Message: CS0103: The name 'xml' does not exist in the current context

Source Error:


Line 19: HttpWebRequest webRequest = null;
Line 20: string response = "";
Line 21: byte[] bytes = Encoding.UTF8.GetBytes(xml);
Line 22:
Line 23: try
Member 9763669 31-Jan-13 9:15am    
kkkj
Sumit_Kumar_Sinha 15-Nov-12 2:17am    
Hey....above code is not working...........please guide me.........i m not getting...how can i solve this.
Member 9763669 31-Jan-13 9:15am    
jkkjjj

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