[英]C# clickatell to send SMS HTTP GET request
我想使用Clickatell服务发送一条简单消息。
我不想读取响应,这将是简单的GET请求以发送消息。
该服务提供的请求如下所示:
https://platform.clickatell.com/messages/http/send?apiKey=xxxxxxxxxxxxxxxx==&to=xxxxxxxxxxx&content=Test+message+text
我卷曲了检查
curl "https://platform.clickatell.com/messages/http/send?apiKey=apiKEY==&to=NUMBER&content=Test+message+text"
而且工作正常。
我尝试通过HTTP请求在Windows窗体应用程序中使用它,下面是我提供的代码:
var client2 = new HttpClient();
client2.GetAsync("https://platform.clickatell.com/messages/http/send?apiKey=apiKEY==&to=NUMBER&content=Test+message+text");
App.Write("SMS SEND!");
我有SMS发送的信息,但没有收到。 我的朋友在.NET应用程序中使用我的代码,它正在为他工作。
我想念什么吗?
也许真的值得一提,我需要使用System.Net.Http手动添加到References;
编辑:
我尝试添加以使其异步执行,因此我将代码编辑为:
static void sendSMS()
{
var client2 = new HttpClient();
var task = client2.GetAsync("https://platform.clickatell.com/messages/http/send?apiKey=API_KEY==&to=MY_NUMBER&content=Test+message+text");
task.Wait();
App.Write("SMS SEND!");
}
但是现在不显示应用程序中的SMS SEND消息。
好吧,我知道您使用的是.NET 4.5,并且您可能有问题
“基础连接已关闭:发送中发生意外错误”
正确的代码如下所示:(必须在请求前添加'SecurityProtocol'):
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
var client2 = new HttpClient(); client2.GetAsync("https://platform.clickatell.com/messages/http/send?apiKey=apiKEY==&to=NUMBER&content=Test+message+text").Result;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.