在我的网络应用程序中我使用api发送短信,你的单个电话号码工作正常,但我的要求是我想发送短信到两个电话号码(手机号码)可以帮助我。当用户来时到我的网站并注册autometically管理员将获得短信警报,现在我想同时发送短信。
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
mobile =Server.HtmlEncode ( txtMobile.Text);
message = Server.HtmlEncode(txtMessage.Text);
username = Server.HtmlEncode(txtName.Text);
password = Server.HtmlEncode(txtPassword.Text);
domian = Server.HtmlEncode(txtDomain.Text);
string result = apicall("http://"+domian+"/pushsms.php?username="+username+"&password="+password+"&sender=&to="+mobile+"&message="+message);
if (!result.StartsWith("Wrong Username or Password"))
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sent')", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sending Failed')", true);
}
sentMail()
}
catch
{
}
}
public void sentMail() { string mobile =“9701098107”; string message =“test”; string username =“xxx”; string password =“yyyy”; string domian =“smsftt.com”; string result1 = apicall(“http://”+ domian +“/pushsms.php?username =”+ username +“& password =”+ password +“& sender =& to =”+ mobile +“& ; message =“+ message); }
public string apicall(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";
}
}
答案 0 :(得分:0)
这不仅仅是用不同的细节再次制作apicall那么简单吗?更改您传入的手机号码和完成的工作......
答案 1 :(得分:0)
您可以使用此代码对我来说工作正常,请将以下代码保存在函数调用中,该函数使用CSV分隔的多个移动号码
string stringpost = "Here username password and type of sms as querystring";
HttpWebRequest objWebRequest = null;
HttpWebResponse objWebResponse = null;
StreamWriter objStreamWriter = null;
StreamReader objStreamReader = null;
try
{
string stringResult = null;
objWebRequest = (HttpWebRequest)WebRequest.Create("http://'your sms api'");
objWebRequest.Method = "POST";
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream());
objStreamWriter.Write(stringpost);
objStreamWriter.Flush();
objStreamWriter.Close();
objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
objWebResponse = (HttpWebResponse)objWebRequest.GetResponse();
objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
stringResult = objStreamReader.ReadToEnd();
objStreamReader.Close();
return (stringResult);
}
catch (Exception ex)
{
return (ex.ToString());
}
finally
{
if ((objStreamWriter != null))
{
objStreamWriter.Close();
}
if ((objStreamReader != null))
{
objStreamReader.Close();
}
objWebRequest = null;
objWebResponse = null;
}