2017-10-19 219 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