Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exemple en VB d'envoi de fax unitaire
Public Sub Main(ByVal Args() As String)
' Récupération du document en base64
' ---------------------------------------
Dim filename As String = "test-fax.doc"
Dim file() As Byte = System.IO.File.ReadAllBytes(filename)
Dim binary As String = System.Convert.ToBase64String(file, 0, file.Length)
' Création du XML à poster
' --------------------------
Dim xml As String = "<request login=""your-login"" password=""your-password"">" & _
"<push media=""fax"" type=""on_demand"" name=""Test API Fax VB.NET"">" & _
"<message type=""doc"">" & binary & "</message>" & _
"<recipients>" & _
"<add target=""+33 170248254"" />" & _
"</recipients>" & _
"</push>" & _
"</request>"
' Construction et envoi de la requête HTTP
' ------------------------------------------
Dim request As WebRequest = WebRequest.Create("http://api.express-mailing.com/transac/api.ashx")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Dim byteArray() As Byte = System.Text.Encoding.UTF8.GetBytes(xml)
request.ContentLength = byteArray.Length
Dim dataStream As System.IO.Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
Dim responseStream = response.GetResponseStream()
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(responseStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
End Sub
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.