using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json;
class Message
{
public string text { get; set; }
public string pushtype { get; set; }
public string sender { get; set; }
public string delay { get; set; }
}
class Phone
{
public string gsmsmsid { get; set; }
public string value { get; set; }
}
class Payload
{
public SMS sms{ get; set; }
public Payload() //default contructor
{
this.sms = new SMS();
}
}
class Recipients
{
public List gsm{ get; set;}
public Recipients()
{
this.gsm = new List();
}
}
class SMS
{
public Message message{ get; set; }
public Recipients recipients{ get; set;}
public SMS()
{
this.recipients = new Recipients();
}
}
public class Program
{
public static void Main()
{
string token = "your.token"; //Your first token must be generated on our plateform at https://app.smsup.ch/developers/api-tokens
Message msgObj = new Message()
{
text = "Votre message",
pushtype = "alert",
sender = "DOTNET"
};
Phone phoneObj = new Phone()
{
value = "41781234567"
};
Payload payloadObj = new Payload();
payloadObj.sms.message = msgObj;
payloadObj.sms.recipients.gsm.Add(phoneObj);
string jsonData = JsonConvert.SerializeObject(payloadObj);
Console.WriteLine(jsonData);
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.smsup.ch");
httpWebRequest.Accept = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add("Authorization", "Bearer " + token);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(jsonData);
streamWriter.Flush();
streamWriter.Close();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Console.WriteLine(result);
}
}
}