Reputation: 2012
May be that's not a real question but i need help as i am tired of doing this. I want to send sms from my c# windows application, i read many blogs and i found some code also but that's not working. I am referring this link for using API
http://ubaid.tk/api-usage/
and my code is:
public void send(string uid, string password, string message, string no)
{
try
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=fullonsms");
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
respStreamReader.Close();
myResp.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
string msg = ex.ToString();
}
}
but it gives me this error:
System.Net.WebException: The operation has timed out at system.Net.HttpWebRequest.GetResponse()
I don't know how to solve this error.I need help and if someone has any other better link please share that.
Thanks a lot in advance for help.
Upvotes: 0
Views: 3431
Reputation: 749
SMS API CLASS::
#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Configuration;
using System.Net;
using System.IO;
using SendBirthdaySMS;
#endregion
/// <summary>
/// Summary description for SMSAPI
/// </summary>
public class SMSAPI
{
MyConnection con = new MyConnection();
public DataSet ds = new DataSet();
public SqlDataAdapter da = new SqlDataAdapter();
public SMSAPI()
{
//
// TODO: Add constructor logic here
//
}
/*Get The SMS API*/
public string GETSMSAPI()
{
con.Open();
string QuerySMS, StringSMS, APISMS, UserName, Password, Sender, Priority;
QuerySMS = "SP_SMSAPIMaster_GetDetail";
StringSMS = APISMS = UserName = Password = Sender = Priority = "";
con.cmd.CommandText = QuerySMS;
try
{
con.Open();
con.cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(con.cmd);
da.Fill(ds, "tbl_SMSAPIMaster");
if (ds.Tables["tbl_SMSAPIMaster"].Rows.Count > 0)
{
APISMS = ds.Tables["tbl_SMSAPIMaster"].Rows[0]["SMSAPI"].ToString();
UserName = ds.Tables["tbl_SMSAPIMaster"].Rows[0]["UserName"].ToString();
Password = ds.Tables["tbl_SMSAPIMaster"].Rows[0]["Password"].ToString();
Sender = ds.Tables["tbl_SMSAPIMaster"].Rows[0]["Sender"].ToString();
Priority = ds.Tables["tbl_SMSAPIMaster"].Rows[0]["Priority"].ToString();
StringSMS = APISMS.Replace("uid", UserName).Replace("psd", Password).Replace("sndid", Sender).Replace("prt", Priority);
}
else
{
StringSMS = "";
}
}
catch
{
}
finally
{
con.Close();
}
return StringSMS;
}
/*Call The SMS API*/
public string GetAPICALL(string url)
{
HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);
try
{
HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();
StreamReader sr = new StreamReader(httpres.GetResponseStream());
string results = sr.ReadToEnd();
sr.Close();
return results;
}
catch
{
return "0";
}
}
}
private void SendBirthdaySMS(string lbl_MobileNo)
{
#region For Employee Message Content..!!
string Msgs, SMSString;
Msgs = SMSString = "";
SMSString = SMSAPI.GETSMSAPI();
Msgs = "Hello";
lblMessageContent.Text = Msgs;
SMSString = SMSString.Replace("num", lbl_MobileNo).Replace("fedmesge", Msgs);
string Result = SMSAPI.GetAPICALL(SMSString);
#endregion
}
Upvotes: 0
Reputation: 184
So looking at the sms site, it says that their services are being IP Blocked. It does not specify whether the IP block is from the cell companies or if it is from the ISP's so that could be a problem. It also says that they experience down time, so it may be that their server is down. It also may be that their servers are slow and that your program just times out too fast.
Upvotes: 1