Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.