如何发送短信到不同的电话号码 [英] How to send SMS to different Phone number

查看:189
本文介绍了如何发送短信到不同的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从asp.net发送短信到不同的电话号码的要求,我绝对没有发送短信的想法。但通过谷歌我有这片code的:

i have a requirement of sending sms to different phone number from asp.net and I have absolutely no idea of sending sms. But through google i have got this piece of code :

   using System;
   using System.Collections.Generic;
   using System.Configuration;
   using System.Data;
   using System.Linq;
   using System.Web;
   using System.Web.Security;
   using System.Web.UI;
   using System.Web.UI.HtmlControls;
   using System.Web.UI.WebControls;
   using System.Web.UI.WebControls.WebParts;
   using System.Xml.Linq;
   using System.Net;


 namespace TESTING
  {
public partial class SendSMS : System.Web.UI.Page
{
    string uid;
    string password;
    string message;
    string no;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void send()
    {
    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();
}

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        uid = "";
        password = "";
        message = MessageTextBox.Text;
        no = MobileNumberTextBox.Text;
        send();
        MessageTextBox.Text = "";
        MobileNumberTextBox.Text = "";
    }
    catch (Exception ex)
    {
        ex.Message.ToString();            
    }

}

 }
 }

我有一个ASP code是这样的:

I have a asp code like this:

  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SendSMS.aspx.cs" Inherits="TESTING.SendSMS" %>

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
     <title></title>
    </head>
  <body>
   <form id="form1" runat="server">
    <div>
      <asp:Label ID="Label1" runat="server" Text="Mobile No"></asp:Label>
       <asp:TextBox ID="MobileNumberTextBox" runat="server"></asp:TextBox>
        <br />
          <asp:Label ID="Label2" runat="server" Text="Message"></asp:Label>
            &nbsp;&nbsp;
            <asp:TextBox ID="MessageTextBox" runat="server" TextMode="MultiLine">                     </asp:TextBox>
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Text="Send Sms" OnClick="Button1_Click" />
      </div>
     </form>
   </body>

这片code的不wroking发送短信。我需要一个code样品发送短信。您的帮助意味着很多给我。

this piece of code is not wroking for sending sms. I need a code sample to send the sms. Your help means a lot to me.

推荐答案

您没有传递信息,密码,不,UID的文本框值发送()功能。
 aspx文件似乎罚款。做CS文件的变化如下图所示。

You were not passing text box values of message , password , no , uid to send() function. aspx file seems fine. do changes in cs file like below.

对于不太code的缘故,我已经取代的HttpWebRequest 类下载网址Web客户端类。结果
Web客户端类提供了大部分所提供的功能的HttpWebRequest 类。

For sake of less code ,I have replaced HttpWebRequest class with WebClient class for downloading url .
WebClient class provides for most of functionality provided by HttpWebRequest class.

有关两者比较,看到这个话题。

   using System;
   using System.Collections.Generic;
   using System.Configuration;
   using System.Data;
   using System.Linq;
   using System.Web;
   using System.Web.Security;
   using System.Web.UI;
   using System.Web.UI.HtmlControls;
   using System.Web.UI.WebControls;
   using System.Web.UI.WebControls.WebParts;
   using System.Xml.Linq;
   using System.Net;


 namespace TESTING
{
public partial class SendSMS : System.Web.UI.Page
{
    string uid;
    string password;
    string message;
    string no;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void send(string message ,string no,string password,string uid )
    {

     using (WebClient cli = new WebClient())
    {
      url =@"http://ubaid.tk/sms/sms.aspx?uid=" + uid + "&pwd=" + password + "&msg=" + message + "&phone=" + no + "&provider=fullonsms";
      cli.DownloadString(url);

    }

    }

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        uid = "";
        password = "";
        message = MessageTextBox.Text;
        no = MobileNumberTextBox.Text;
        send(message ,no,password,uid );
        MessageTextBox.Text = "";
        MobileNumberTextBox.Text = "";
    }
    catch (Exception ex)
    {
        ex.Message.ToString();            
    }

}

 }
 }

我已经使用 Web客户端类present在 System.Net 命名空间会下载指定的网址

通过串的网址
DownloadString()功能。

I have used WebClient class present in System.Net namespace which downloads the web address specified in string url by its DownloadString() function .

在这里看到WebClient类

这篇关于如何发送短信到不同的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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