如何在asp.net中使用way2sms发送短信 [英] how to send sms using way2sms in asp.net

查看:80
本文介绍了如何在asp.net中使用way2sms发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的编码使用way2sms从asp.net发送短信但我无法发送,我收到错误,如错误发送消息....检查你的连接......

i有way2sms的登录帐户,即使我能够直接从way2sms网站发送msg,但在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 = "";
    }

推荐答案

这应该对你有帮助 -

发送短信到手机 [ ^ ]
this should help you-
send sms to mobile[^]


<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();
    }


System.Net.WebException:远程服务器返回错误:(404)Not Found。在System.Net.HttpWebRequest.GetResponse()
System.Net.WebException: The remote server returned an error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse()


这篇关于如何在asp.net中使用way2sms发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆