缺乏从响应的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;
}
}
}
希望这可以帮助别人....