Skip to content

Instantly share code, notes, and snippets.

@thuma
Created November 17, 2015 13:38
Show Gist options
  • Save thuma/c6da6bd1c45e424173b6 to your computer and use it in GitHub Desktop.
Save thuma/c6da6bd1c45e424173b6 to your computer and use it in GitHub Desktop.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace elktest {
class Program {
public static string user = "<API Username>";
public static string pwd = "<API Password>";
private static HttpClient client;
static void Main(string[] args)
{
Task.Run(async() = > {
using(client = new HttpClient()) {
client.BaseAddress = new Uri("https://api.46elks.com");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
"Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", user, pwd))));
var content = new FormUrlEncodedContent(new[] {
new KeyValuePair < string, string > ("from", "+46723175800"),
new KeyValuePair < string, string > ("to", "+46735417172"),
new KeyValuePair < string, string > ("message", "Test 😊"),
});
HttpResponseMessage response = await client.PostAsync("/a1/SMS", content);
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
}
}).Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment