Skip to main content

Hi !

We are using Visual Basic 6 to Send Http post request But unfortunaly the client receive empty Fax. here is our Base Code


Function CreateFaxMessage(strPath, _                            strStatus, _                            Receiver, _                            Optional coverPageText = "", _                            Optional strResponse = "", _                            Optional faxResolution As String = "High") As Boolean          '<EhHeader>          On Error GoTo CreateFaxMessage_Err          '</EhHeader>    100     If Not isLoggedIn Then                102         MsgBox "Le token daccs est Invalid"                Exit Function            End If                        Dim strFile, strExt, strContentType, strBoundary, bytData, bytPayLoad                On Error Resume Next    104     With CreateObject("Scripting.FileSystemObject")    106         If .FileExists(strPath) Then  108             strFile = .GetFileName(strPath)  110             strExt = .GetExtensionName(strPath)              Else  112             strStatus = "File not found"  114             CreateFaxMessage = False                                Exit Function                End If            End With        116     With CreateObject("Scripting.Dictionary")  118         .Add "txt", "text/plain"  130         .Add "jpeg", "image/jpeg"  132         .Add "jpg", "image/jpeg"  134         .Add "png", "image/png"  138         .Add "doc", "application/msword"  140         .Add "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"  142         .Add "xls", "application/vnd.ms-excel"  144         .Add "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"  146         .Add "pdf", "application/pdf"  148         strContentType = .Item(LCase(strExt))          End With        150     If strContentType = "" Then  152         strStatus = "Invalid file type"  154         CreateFaxMessage = False              Exit Function          End If              174     strBoundary = String(2, "-") & Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")      Dim nFile           As Integer      Dim baBuffer()      As Byte      Dim sPostData       As String             '--- read file      nFile = FreeFile      Open strPath For Binary Access Read As nFile      If LOF(nFile) > 0 Then          ReDim baBuffer(0 To LOF(nFile) - 1) As Byte          Get nFile, , baBuffer          sPostData = StrConv(baBuffer, vbFromUnicode)      End If      Close nFile      '--- prepare body          sPostData = strBoundary & vbCrLf & _          "Content-Disposition: form-data; name=""attachment""; filename=""" & strFile & """" & vbCrLf & _          "Content-Transfer-Encoding: binary" & vbCrLf & _          "Content-Type: " & strContentType & vbCrLf & vbCrLf & _          sPostData & vbCrLf          sPostData = sPostData & strBoundary & "--"                                      Dim params As String           220     params = strBoundary & vbCrLf  222     params = params & "Content-Disposition: form-data; name=""faxResolution""" & vbCrLf & vbCrLf  224     params = params & faxResolution & vbCrLf            232     params = params & strBoundary & vbCrLf          params = params & "Content-Disposition: form-data; name=""to""" & vbCrLf & vbCrLf          params = params & Receiver & vbCrLf                                        Dim XMLHTTP As Object    218     Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")    240     With XMLHTTP  242         .setTimeouts 0, 60000, 300000, 300000  244         .Open "POST", FaxURL, False  246         '.setRequestHeader "Accept", "application/json; boundary=" & strBoundary  248         .setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Mid(strBoundary, 3)  250         .setRequestHeader "Authorization", "Bearer " & RingCentral.AccessToken  252         .send params & sPostData           254        ' If Err.Number <> 0 Then  256          '   strStatus = Err.Description & " (" & Err.Number & ")"             ' Else  258             ' End If    260         If Ok(.status) Then  262             strResponse = .responseText  264             CreateFaxMessage = True                       Else  266             MsgBox .statusText & " (" & .status & ")"              End If                    End With            '<EhFooter>          Exit Function    CreateFaxMessage_Err:          MsgBox Err.Description & vbCrLf & _                 "in Projet1.RingCentralManager.CreateFaxMessage " & _                 "at line " & Erl, _                 vbExclamation + vbOKOnly, "Application Error"          Resume Next          '</EhFooter>  End Function



I cannot program in VB6 and I don't actually understand the code you posted.

I have a question: what the response from the server? Is the status code 200? If not, could you please read the response body out and inspect the reason?

According to my experience writing C# code to send fax, here is a thing for you to try: for the all the key/value parameters, such as "to" and "faxResolution", you can construct a json file and send it as if it is an attachment with name request.json and content type application/json. Code for your reference: https://github.com/ringcentral/RingCentral.Net/blob/master/RingCentral.Tests/FaxTest.cs#L204-L214

Reply