0

可能这不是一个真正的问题,但我需要帮助,因为我厌倦了这样做。我想从我的 c# windows 应用程序发送短信,我阅读了很多博客,我也找到了一些代码,但这不起作用。我指的是这个链接使用 API

http://ubaid.tk/api-usage/

我的代码是:

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

但它给了我这个错误:

System.Net.WebException: The operation has timed out at system.Net.HttpWebRequest.GetResponse()

我不知道如何解决这个错误。我需要帮助,如果有人有任何其他更好的链接,请分享。

非常感谢您的帮助。

4

2 回答 2

1

所以看看短信网站,它说他们的服务被 IP 封锁了。它没有说明 IP 块是来自手机公司还是来自 ISP,所以这可能是个问题。它还说他们经历了停机时间,因此可能是他们的服务器停机了。也可能是他们的服务器很慢,而您的程序超时太快了。

于 2013-06-05T17:04:37.933 回答
0
    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


        }
于 2019-09-02T09:00:03.507 回答