我过去几周一直在使用clickatell服务,每天早上发送短信到多个手机号码,直到今天才出现问题:
System.Net.WebException:底层连接已关闭:发送时发生意外错误。 ---> System.IO.IOException:身份验证失败,因为远程方已关闭传输流。
我尝试过从公司网络内部发送,在它之外,甚至尝试从移动数据连接,每次都得到相同的响应。
我检查了我的clickatell帐户,它仍然有很多功劳,并且整合已经切换到' ..
任何想法出了什么问题?
答案 0 :(得分:0)
在clickatell没有响应后,我做了一些挖掘并找到了这个帖子......
"The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate
当我使用.net 4时,我尝试将这行代码添加到我从clickatell获得的Rest类...
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;
}
}
}
希望这有助于其他人......
答案 1 :(得分:0)
是的,SecurityProtocol必须是Transport Layer Security 1.2(3072它的Tls12 SecurityProtocolType枚举值)。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
使用.net 4.6 Microsoft已升级对ssl的安全限制。
如果您需要更多内容,请阅读:ServicePointManager o SslStream APIs in .net 4.6
抱歉,这篇文章是意大利文,我没有找到英文版。