2017-07-25 59 views
0

我一直在使用的Clickate服务过去几周每天早晨发送短信到多个手机号码的,直到今天没有任何问题:的Clickate未能发送短信 - C#WinForms应用程序

System.Net.WebException:基础连接已关闭:发送时发生意外错误。 ---> System.IO.IOException:由于远程方关闭了传输流,认证失败。

我试过从企业网络内部发送,并且在外面也尝试了移动数据连接,每次都得到相同的响应。

我检查了我的Clickate帐户,它仍然有大量的信贷,并整合为“ON”切换..

任何想法是什么问题呢?

回答

0

缺乏从响应的Clickate后,我做了一些挖了一圈,发现这个线程...

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

由于我使用的是.NET 4,我尝试添加这行代码到其余的I类从的Clickate了......

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

希望这可以帮助别人....

0

是的,SecurityProtocol必须是传输层安全1.2(3072是Tls12 SecurityProtocolType枚举值)。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 

With .net 4.6 Microsoft已经升级了对ssl的安全限制。

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

对不起,这篇文章是在意大利,我没有找到英文版本。