Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Exemple en C# d'envoi de message vocal unitaire
static void Main(string[] args)
// Récupération du document en base64
string filename = "test-audio.wav";
byte[] file = System.IO.File.ReadAllBytes(filename);
string binary = System.Convert.ToBase64String(file, 0, file.Length);
// Création du XML à poster
var xml = @"<request login=""your-login"" password=""your-password"">
<push media=""voice"" type=""on_demand"" name=""Audio fixe ou mobile"">
<message type=""wav"">" + binary + @"</message>
<voice_config sender_id=""0199999999"" />
<add target=""+33 123456789""/>
// Construction et envoi de la requête HTTP
WebRequest request = WebRequest.Create("");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(xml);
request.ContentLength = byteArray.Length;
System.IO.Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
WebResponse web_response = request.GetResponse();
var stream_response = web_response.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(stream_response);
string response = reader.ReadToEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment