News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Empty Fax using VB6
Tags: fax
Sep 24, 2018 at 9:04am   •   1 replies  •  0 likes
rachid-abbouchi

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



1 Answer
answered on Mar 29, 2019 at 6:19pm  
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

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us