Android Question Downloading Internet files with OkHttpUtils2

Doug Thorsvik

Member
Licensed User
I am trying download .mp3 files from the internet. I have tried without success from two different web locations; one requiring a username and password and one that does not. In both cases I get the same error message:

***Error: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

I am not sure what to try next.

The libraries I have installed are: Core (v 8.30), OkHttp (v 1.2), OkHttpUtils2 (v 2.61), RuntimePermissions (v 1.1), and StringUtils (v 1.12)

Here are the two code modules:

Sub DownloadFile
Log("Download File from internet")
Dim job1 As HttpJob
job1.Initialize("Job1", Me)

'job1.Username = "___"
'job1.Password = "_________"
'job1.Download("https://durben.thorsvik.net/remote.php/webdav/music/Kalimba.mp3")

job1.Download("https://gap.thorconsulting.net/joshmusic/song0.mp3")
End Sub

Sub JobDone(Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
Log("File Downloaded")
End Select
Else
Log("***Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
 

Erel

Administrator
Staff member
Licensed User
1. Please use [code]code here...[/code] tags when posting code.

2. You should use Wait For instead of handling the JobDone event.

3. The error means that the site certificate is not recognized. You need to use OkhttpUtils2 source code instead of the library and modify hc.Initialize with hc.InitializeAcceptAll (make a few searches and you will find it).
 

Doug Thorsvik

Member
Licensed User
Erel

Thanks for the help!!!

I incorporated the Wait For code. I was also able to use OkhttpUtils2 source code and modify hc.Initialize successfully.

The code without the password ran and I was able to add additional code to copy the file to the SD card on my tablet. Progress!

Is there a way to get a list of the files in a directory (folder) at a website or do I always have to know the names of the files I want to download?
 

mangojack

Well-Known Member
Licensed User
Whilst this is not an answer to your enquiry .. It is best to start a new thread for your new question.
 

KMatle

Expert
Licensed User
Of course there is no function to get all files on a server (security). You always have to know the absolute path. If you have an own server you can do it with php. I recommend you to install XAMPP to test your apps (small local http server).
 

Doug Thorsvik

Member
Licensed User
Thanks for the inputs.
A new thread would have been more appropriate.
Security is always the issue when dealing with a server.
I am going to try another approach to identifying the files in a specific folder on a website.
 
Top