C# Code Example
HTTP API Code Sample – C#
The code sample below shows you how to send SMS messages quickly using a simple C# snippet based on the HTTP API. The script sends a single 1-way SMS message that will appear to come from "XYZCorp".
Send a 1-Way SMS Using C#
// Import the required libraries using System.Net; using System.IO; // Create a new web client to send the request WebClient client = New WebClient(); // Add the various parameters that need to go out // with the HTTP request client.QueryString.Add("username", "my_username"); client.QueryString.Add("password", "SecrEt12345"); client.QueryString.Add("message", "Hello World"); client.QueryString.Add("type", "1-way"); client.QueryString.Add("senderid", "XYZCorp"); client.QueryString.Add("to", "61400000000"); // Set the URL to send the request to. Please note, // you can use HTTP or HTTPS string url = "http://api.directsms.com.au/s3/http /send_message" // Send the request and read the response Stream stream = client.OpenRead(url); StreamReader reader = New StreamReader(stream); string response = reader.ReadToEnd(); // Close the data stream and HTTP connection stream.Close(); reader.Close(); // The response from the gateway is going to look like // this: // id: a4c5ad77ad6faf5aa55f66a // // In the event of an error, it will look like this: // err: invalid login credentials
The full HTTP/S API documentation details all available features of directSMS' Bulk SMS Gateway. For additional help or if you have any questions, please contact our helpful support team.