2017-10-19 163 views
0

我想使用服务Clickatell发送简单消息。C#clickatell发送短信HTTP GET请求

我不想读取响应,它将简单的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" 

检查了它,它的工作真的很好。

我尝试使用我的Windows使用它形成与HTTP请求 应用下面是我提供的代码:

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!"); 

我有信息即发送短信,但我没有收到。我的朋友在.NET应用程序中使用我的代码,并为他工作。

我想念什么?

也许真的值得一提的是我需要使用System.Net.Http手动添加到引用;

编辑:

我试图添加到做异步,所以我编辑我的代码:

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!"); 
     } 

但现在不显示在应用程序中发送短信消息。

+1

更多细节,我知道你不想读取响应长远但是出于测试和获得它的工作也许你应该 – BugFinder

回答

1

好吧,我知道你使用.NET 4.5,你可能有问题,一个exeption

权代码“的基础连接被关闭一个发送发生意外的错误”它看起来像这样:(您必须reqeust前添加 '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;

这里https://stackoverflow.com/a/32789483/5816153

+0

这是正确的!谢谢。 – P4TRYK