Skip to content

Instantly share code, notes, and snippets.

@expressmailing
Last active January 2, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expressmailing/584052e5bd510b1f801eadb7dcae964c to your computer and use it in GitHub Desktop.
Save expressmailing/584052e5bd510b1f801eadb7dcae964c to your computer and use it in GitHub Desktop.
Exemple en C# d'envoi de fax unitaire
static void Main(string[] args)
{
// Récupération du document en base64
string filename = "test-fax.doc";
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=""fax"" type=""on_demand"" name=""Test API Fax C#"">
<message type=""doc"">" + binary + @"</message>
<recipients>
<add target=""+33 170248254""/>
</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