C# Example

Continuing from the example in Your First Message Template, you can send your transactional message in C# with the following.

var url = "https://txnhog.co/txn/api/your_message_key";

var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";

httpRequest.ContentType = "application/x-www-form-urlencoded";

var data = "apiKey=sdkrjwhaldkgh3pwdfohawp4lyu&name=Shawn%20Spencer&phone=2085559988";

using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{
   streamWriter.Write(data);
}

var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
   var result = streamReader.ReadToEnd();
}

Console.WriteLine(httpResponse.StatusCode);

Last updated