【问题标题】:Clickatell Failing to send SMS - c# Winforms ApplicationClickatell 发送短信失败 - c# Winforms 应用程序
【发布时间】:2017-07-25 08:11:59
【问题描述】:

过去几周我一直在使用 clickatell 服务,每天早上向多个手机号码发送短信,直到今天没有问题:

System.Net.WebException:底层连接已关闭:发送时发生意外错误。 ---> System.IO.IOException: 身份验证失败,因为远程方已关闭传输流。

我尝试过从公司网络内部发送,外部也尝试过,甚至尝试通过移动数据连接,每次都得到相同的响应。

我检查了我的 clickatell 帐户,它仍然有足够的信用,并且集成已“开启”..

有什么想法吗?

【问题讨论】:

    标签: c# winforms sms clickatell


    【解决方案1】:

    在clickatell没有回复之后,我做了一些挖掘,发现了这个线程......

    "The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate

    当我使用 .net 4 时,我尝试将这行代码添加到我从 clickatell 获得的 Rest Class...

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    

    添加此代码似乎使系统再次工作..

    所以,如果您使用的是 .net4 和 REST api,这就是您需要的代码:

    class Rest
    {
        //This takes the API Key and JSON array of data and posts it to the Message URL to send the SMS's
        public static string Post(string Token, string json)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://platform.clickatell.com/messages");
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
            httpWebRequest.Accept = "application/json";
            httpWebRequest.PreAuthenticate = true;
            httpWebRequest.Headers.Add("Authorization", Token);
    
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                return result;
            }
       }
    }
    

    希望这对其他人有所帮助....

    【讨论】:

      【解决方案2】:

      是的,SecurityProtocol 必须是 Transport Layer Security 1.2(3072 它是 Tls12 SecurityProtocolType 枚举值)。

      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
      

      随着 .net 4.6,微软升级了对 ssl 的安全限制。

      如果您想了解更多,请阅读:ServicePointManager o SslStream APIs in .net 4.6

      抱歉,这篇文章是意大利语的,我没找到英文版。

      【讨论】:

        猜你喜欢
        • 2013-01-22
        • 1970-01-01
        • 1970-01-01
        • 2016-07-03
        • 2017-06-23
        • 1970-01-01
        • 1970-01-01
        • 2012-05-04
        • 1970-01-01
        相关资源
        最近更新 更多