I want to send a simple message using the service Clickatell.
I don't want to read the response, it will be simple GET request to send a message.
The service provides the request looks like:
https://platform.clickatell.com/messages/http/send?apiKey=xxxxxxxxxxxxxxxx==&to=xxxxxxxxxxx&content=Test+message+text
I checked it with curl
curl "https://platform.clickatell.com/messages/http/send?apiKey=apiKEY==&to=NUMBER&content=Test+message+text"
and it's working really fine.
I try to use it with my Windows Forms application with HTTP request Below is the code which I provided:
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!");
I have info that SMS send, but I didn't receive it. My friend use my code in the .NET application and it's working for him.
Do I miss something?
Maybe it's really worth to mention I need to add to References manually using System.Net.Http;
EDIT:
I tried to add to do it async, so I edit my code to:
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!");
}
But now the SMS SEND message in the application is not shown.
Ok I know You use .NET 4.5 and You probably have problem with a exeption
"The underlying connection was closed: An unexpected error occurred on a send"
The right code it looks like this: (You must add 'SecurityProtocol 'before reqeust):
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;
More details herehttps://stackoverflow.com/a/32789483/5816153