在clickatell没有回应之后,我做了一些挖掘,发现了这个线程......
“底层连接已关闭:发送时发生意外错误。” 使用 SSL 证书
当我使用.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;
}
}
}
希望这对其他人有帮助....