开发者

sending multiple sms in asp.net?

In my web applicatin i am using api for sending sms, ya it is working fine for single phone number, but my requirement is i want to send sms to two phone numbers(mobile numbers)can u help me.when user come to my site and register autometically admin will get sms alert, now i want to send sms at the same time.

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开发者_JAVA百科')", 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";
    }
}


Is this not just as simple as making that apicall again with different details? Change the mobile number you pass in and job done...


You can use this code its working fine for me , keep the below code in function call that function with the multiple mobile numbers separated in 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;
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜