Created
January 4, 2018 16:05
-
-
Save expressmailing/881a1b5ab9a6a0d8e87c7a907c17eb14 to your computer and use it in GitHub Desktop.
Exemple en C# d'envoi de message vocal unitaire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"" /> | |
<recipients> | |
<add target=""+33 123456789""/> | |
</recipients> | |
</push> | |
</request>"; | |
// Construction et envoi de la requête HTTP | |
WebRequest request = WebRequest.Create("http://api.express-mailing.com/transac/api.ashx"); | |
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); | |
dataStream.Close(); | |
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(); | |
Console.WriteLine(response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment