I have trouble downloading a binary from a https server with basic http auth. I cannot find the error in LastError.txt. I can use the same credentials and URL with a browser and if I change my code to download from a http instead of a https server and remove the basic auth (not required for the URL I tested), the code is working fine.
It's obvious from LastError.txt that there's a 401 Unauthorized. But I set the correct Username and Password.
BTW: Looking at some other (working) Chilkathttp based https requests to the same server (which are not downloading binary files), I think I must have overseen some option to tell Chilkathttp to immediately provide http auth information rather than first trying without and then retrying after a 401 was received. Looking at LastErrorTXT from those requests I think that there's always a request without http auth information and only after the 401 an additional request including the http basic auth information is being sent.
This is the code I use, it's based on this example:
Option Explicit Dim WithEvents http As ChilkatHttp Dim bAbort As Boolean Private Sub AbortBtn_Click() bAbort = True End Sub Private Sub Command1_Click() Dim success As Long Set http = New ChilkatHttp ' Any string unlocks the component for the 1st 30-days. success = http.UnlockComponent("Anything for 30-day trial") If (success <> 1) Then MsgBox http.LastErrorText Exit Sub End If http.HeartbeatMs = 100 http.login = "Username" http.Password = "TheRightPassword" ProgressBar1.value = 0 bAbort = False AbortBtn.SetFocus success = http.Download("https://www.domain.com/downloads/TheFile.exe", "c:\temp\foo.exe") If (success <> 1) Then Debug.Print http.LastErrorText MsgBox "Error downloading" Else Debug.Print "Download in progress" End If End Sub Private Sub http_AbortCheck(abort As Long) If (bAbort) Then abort = 1 DoEvents End Sub Private Sub http_EndReceive(ByVal success As Long) Debug.Print "download completed" End Sub Private Sub http_PercentDone(ByVal percent As Long, abort As Long) ProgressBar1.value = percent End Sub
This is LastError.txt:
download completed ChilkatLog: Download: DllDate: Jun 23 2015 ChilkatVersion: 22.214.171.124 UnlockPrefix: Anything for 30-day trial Username: MyHostName:MyUserName Architecture: Little Endian; 32-bit Language: ActiveX VerboseLogging: 0 url: https://www.domain.com/downloads/TheFile.exe toLocalPath: c:tempfoo.exe currentWorkingDir: C:temp1 a_httpDownload: httpDownloadFile: localFilePath: c:tempfoo.exe localFileAlreadyExists: 0 quickHttpRequest: httpVerb: GET url: https://www.domain.com/downloads/TheFile.exe openHttpConnection: Opening connection directly to HTTP server. httpHostname: www.domain.com httpPort: 443 ssl: 1 HTTPS secure channel established. --openHttpConnection buildQuickRequest: genStartLine: startLine: GET /downloads/TheFile.exe HTTP/1.1 --genStartLine addCookies: Not auto-adding cookies. sendCookies: 1 cookieDir: --addCookies --buildQuickRequest sendRequestHeader: sendHeaderElapsedMs: 16 --sendRequestHeader statusCode: 401 statusText: Unauthorized readResponseBody: contentLength: 364 --readResponseBody checkCloseConnection: Response includes connection:close header (or proxy-connection:close header) --checkCloseConnection --quickHttpRequest --httpDownloadFile --a_httpDownload totalElapsedMs: 360 ContentLength: 364 Failed. --Download --ChilkatLog
asked Jul 27 '15 at 15:51
Got a solution from Chilkat:
Default behaviour will probably be changed in a future version but for now it's sufficient to just add
answered Aug 04 '15 at 05:47