static void Main(string[] args) { var sendRequest = new SendRequest { SourceAddr = "Kurtename", DestAddr = "9647504958807", MessageText = "Test SMS", Unicode = false }; Console.WriteLine("SOURCE: {0} | DESTINATION: {1} | TEXT: {2} | UNICODE: {3}", sendRequest.SourceAddr, sendRequest.DestAddr, sendRequest.MessageText, sendRequest.Unicode); var sendService = new SendService(); var sendResponse = sendService.Submit(sendRequest).Result; Console.WriteLine("STATUS: {0} | DESCRIPTION: {1} | MESSAGE_ID: {2}", sendResponse.Status, sendResponse.Description, sendResponse.MessageId); }
public async Task <SendResponse> Submit(SendRequest sendRequest) { var jsonInString = JsonConvert.SerializeObject(sendRequest); try { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("x-api-key", X_API_KEY); var httpResponse = await httpClient.PostAsync(URI, new StringContent(jsonInString, Encoding.UTF8, "application/json")); var contentString = await httpResponse.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <SendResponse>(contentString)); } } catch (Exception ex) { Console.WriteLine(ex.Message, ex.StackTrace, "Failed to send SMS"); return(null); } }