Android Question (solved) OkHttpUtils2 repeated download of a file fails, HttpUtils2 succeeds

mc73

Well-Known Member
Licensed User
Longtime User
While developing a port for a web site, used to download some files from it, I noticed that if I try to repeat the donwload process, I got an error from the server. Of course, I used okHTTPUtils2.

Interestingly enough, switching to the old httpUtils2, I had no problem at all with repeated downloads!

Now, I really don't want to use the old deprecated routines, but seems for now, that I can't get okHttpUtils2 to handle correctly the case. In fact, I'm not that much interested in repeated downloads, but unfortunately I have to download other files from the same site, and the result is still the same (fail).
If, however, I completely exit the app (killing it from the task manager) everything works ok again for the first time. Finally, even if clear the cache of the login webview and remove cookies, the same problem arises.

Anyone else experienced this behavior? I can provide the download source code, by private message, since it contains sensitive login information.
 

DonManfred

Expert
Licensed User
Longtime User
It failes about WHAT reason? Did you get any Error in Jobdone? Did you check the error if Job.success is false?
Post the error you got.
Anyone else experienced this behavior?
no
I can provide the download source code, by private message, since it contains sensitive login information
check pn
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Which error do you get?
At first run, I get no error at all, download proceeds.
At second run, I get this:
B4X:
ResponseError. Reason: Internal Server Error, Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an unknown error, possibly due to misconfiguration.
Contact the server administrator: [no address given]<p>
More information about this error may be available
in the server error log.</p>
</body></html>
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I tried your sample.
I can not read what i see on the webpage displayed (ißm not able to read greek). But.
I clicked on the repeat button, the page is reloaded and after the successfully login a pdf viewer want start... i pressed back-key at this point (not interested in the pdf).
I clicked again on the Repeat button... Login and download and open a pdf starts again.
I can repeat....

Logger verbunden mit: 9885e6514556383552
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
url=https://l[..]0911116A1D837211F07D87929B064DFB3D1EA982E271CF8F
url=https://[..]/login.jsp
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
url=https://[..]/home.htm
url=https://[..]applications.htm
url=https://[..]/index.jsp
url=https://[..]/login.done
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
url=https://[..]/home.htm
url=https://[..]/applications.htm
url=https://[..]/index.jsp
url=https://[..]/login.done
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
url=https://[..]/home.htm
url=https://[..]/applications.htm
url=https://[..]/index.jsp
url=https://[..]/login.done
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I tried your sample.
I can not read what i see on the webpage displayed (ißm not able to read greek). But.
I clicked on the repeat button, the page is reloaded and after the successfully login a pdf viewer want start... i pressed back-key at this point (not interested in the pdf).
I clicked again on the Repeat button... Login and download and open a pdf starts again.
I can repeat....

Logger verbunden mit: 9885e6514556383552
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
url=https://l[..]0911116A1D837211F07D87929B064DFB3D1EA982E271CF8F
url=https://[..]/login.jsp
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
url=https://[..]/home.htm
url=https://[..]applications.htm
url=https://[..]/index.jsp
url=https://[..]/login.done
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
url=https://[..]/home.htm
url=https://[..]/applications.htm
url=https://[..]/index.jsp
url=https://[..]/login.done
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
url=https://[..]/home.htm
url=https://[..]/applications.htm
url=https://[..]/index.jsp
url=https://[..]/login.done
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **

In the sample I sent, I've checked http and httpUtils2, so it's working! Have you tried using okHttp and okHttpUtils2 instead?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to clear the cookies. This can be done with this code:
B4X:
If HttpUtils2Service.hc.IsInitialized Then
       Dim jo As JavaObject = HttpUtils2Service.hc
       jo = jo.GetFieldJO("client").RunMethod("cookieJar", Null)
       Dim r As Reflector
       r.Target = jo
       Dim CookieManager As JavaObject = r.GetField("cookieHandler")
       CookieManager.RunMethodJO("getCookieStore", Null).RunMethod("removeAll", Null)
   End If
You need to remove OkHttpUtils2 library and replace it with the two code modules. Make HttpUtils2Service.hc a public variable.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You need to clear the cookies. This can be done with this code:
B4X:
If HttpUtils2Service.hc.IsInitialized Then
       Dim jo As JavaObject = HttpUtils2Service.hc
       jo = jo.GetFieldJO("client").RunMethod("cookieJar", Null)
       Dim r As Reflector
       r.Target = jo
       Dim CookieManager As JavaObject = r.GetField("cookieHandler")
       CookieManager.RunMethodJO("getCookieStore", Null).RunMethod("removeAll", Null)
   End If
You need to remove OkHttpUtils2 library and replace it with the two code modules. Make HttpUtils2Service.hc a public variable.
thank you Erel! This means however that every time this lib is updated I have to manually repeat the process. Any chance that clearing cookies can be set using a method?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Using the above code indeed solved the problem. Once again, thank you very much, Erel!
 
Upvote 0
Top