Hi !
i'm trying to send PDF file using MSXML2.xmlhttp but the client receive empty pdf File as an attachement without any errors. i'm using Visual basic 6.0 to send requests. i sent the same file with RingCentral Web APP and it works. i think the binary conversion is not working proprely here is my code
Function CreateFaxMessage(strPath, _  strStatus, _Receiver, _Optional coverPageText = "", _Optional strResponse = "", _Optional faxResolution As String = "High") As BooleanDim strFile, strExt, strContentType, strBoundary, bytData, bytPayLoadOn Error Resume Next104 With CreateObject("Scripting.FileSystemObject")106 If .FileExists(strPath) Then108 strFile = .GetFileName(strPath)110 strExt = .GetExtensionName(strPath)Else112 strStatus = "File not found"114 CreateFaxMessage = FalseExit FunctionEnd IfEnd With116 With CreateObject("Scripting.Dictionary")146 .Add "pdf", "application/pdf"148 strContentType = .Item(LCase(strExt))End With150 If strContentType = "" Then152 strStatus = "Invalid file type"154 CreateFaxMessage = FalseExit FunctionEnd If174 strBoundary = String(2, "-") & Replace(Mid(CreateObject("Scriptlet.TypeLib").Guid, 2, 36), "-", "")Dim nFile As IntegerDim baBuffer() As ByteDim sPostData As String'--- read filenFile = FreeFileOpen strPath For Binary Access Read As nFileIf LOF(nFile) > 0 ThenReDim baBuffer(0 To LOF(nFile) - 1) As ByteGet nFile, , baBuffersPostData = StrConv(baBuffer, vbFromUnicode)End IfClose nFile'--- prepare bodysPostData = strBoundary & vbCrLf & _"Content-Disposition: form-data; name=""attachment""; filename=""" & strFile & """" & vbCrLf & _"Content-Transfer-Encoding: binary" & vbCrLf & _"Content-Type: " & strContentType & vbCrLf & vbCrLf & _sPostData & vbCrLfsPostData = sPostData & strBoundary & "--"Dim params As String220 params = strBoundary & vbCrLf222 params = params & "Content-Disposition: form-data; name=""faxResolution""" & vbCrLf & vbCrLf224 params = params & faxResolution & vbCrLf232 params = params & strBoundary & vbCrLfparams = params & "Content-Disposition: form-data; name=""to""" & vbCrLf & vbCrLfparams = params & Receiver & vbCrLfDim XMLHTTP As Object218 Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")240 With XMLHTTP242 .setTimeouts 0, 60000, 300000, 300000244 .Open "POST", FaxURL, False246 '.setRequestHeader "Accept", "application/json; boundary=" & strBoundary248 .setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Mid(strBoundary, 3)250 .setRequestHeader "Authorization", "Bearer " & RingCentral.AccessToken252 .send params & sPostData260 If Ok(.status) Then262 strResponse = .responseText264 CreateFaxMessage = TrueElse266 MsgBox .statusText & " (" & .status & ")"End IfEnd WithExit FunctionEnd Function
