Send request hanving authorization to download file with vba

Viewed 21

When sending a request to the server, the excel file will be downloaded. This request has Authorization because login is required. I want to download this file by sending this request in vba. I used this code

Dim request As New WinHttpRequest
Dim url, path As String
url = "https://xxx/query/invoices/export-excel?sort=tdlap:desc,khmshdon:asc,shdon:desc&search=tdlap=ge=23/08/2022”
With request
    .Open "GET", url, False
    .setRequestHeader "Authorization", "Bearer " & Sheet2.Range("A2").Value
    .Send
    .WaitForResponse 2000
End With

request.Status = 200 but the file is not downloaded I continue to use the following way

Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

however "URLDownloadToFileA" doesn't have header Authorization Please help me !!! Thank very much

0 Answers
Related