Android Question OKHttpUtils2, Progress_Sub and POST Request?

Moosi

Member
Licensed User
Longtime User
Hi all,

I´m looking for a solution to download a large file (>50MB) with progress.
But I need to send the Request as POST string.

Does someone has an Idea how to do this?

thanks in advance
Moosi
 

Moosi

Member
Licensed User
Longtime User
Thanks a lot, it works.

This is what I did, just in case someone looks for the same.

In DonwnloadService I changed the DownloadData from:

B4X:
Type DownloadData (url As String, Target As Object, EventName As String)
to
B4X:
Type DownloadData (url As String, Target As Object, EventName As String, PostString As String)
So I added the PostString to the Type

then I changed the
Public Sub StartDownload(data As DownloadData)
where I replaced the J.Download(data.url) with:
B4X:
    If data.PostString.Length > 0 Then
        J.PostString(data.url,data.PostString)
    Else
        J.Download(data.url)
    End If

The call is now:
B4X:
    Dim dd As DownloadData
    dd.url = "MyURL"
    dd.EventName = "EventName"
    dd.Target = Me
    dd.PostString = ""  <--- This is now needed
    CallSubDelayed2(DownloadService, "StartDownload", dd)

That way I can pass an empty PostString to use the HTTP GET but when I pass a Value it uses the HTTP POST.
One thing to note, you need to pass the empty value, otherwise it would be NULL and throw an error.

Maybe it helps someone...
 
Upvote 0
Top