Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exemple en VB 4/5/6 d'envoi de fax unitaire
Private Sub Form_Load()
' Récupération du document en base64
' ---------------------------------------
Dim filename As String, file() As Byte, filnum As Integer, binary As String
filename = "test-fax.doc"
filnum = FreeFile()
Open filename For Binary As filnum
file = InputB(LOF(filnum), #filnum)
Close filenum
binary = EncodeBase64(file)
' Création du XML à poster
' --------------------------
Dim xml As String
xml = "<request login=""your-login"" password=""your-password"">" & _
"<push media=""fax"" type=""on_demand"" name=""Test API Fax VB6"">" & _
"<message type=""doc"">" & binary & "</message>" & _
"<recipients>" & _
"<add target=""+33 170248254"" />" & _
"</recipients>" & _
"</push>" & _
"</request>"
' Construction et envoi de la requête HTTP
' ------------------------------------------
Dim postURL As String
postURL = "http://api.express-mailing.com/transac/api.ashx"
With CreateObject("MSXML2.XMLHTTP")
.open "POST", postURL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send (xml)
response = .responseText
End With
MsgBox (response)
End Sub
Private Function EncodeBase64(ByRef binary() As Byte) As String
Dim objXML, objNode
Set objXML = CreateObject("Microsoft.XMLDOM")
Set objNode = objXML.createElement("doc")
objNode.dataType = "bin.base64"
objNode.nodeTypedValue = binary
EncodeBase64 = objNode.Text
Set objNode = Nothing
Set objXML = Nothing
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment