Android Question Problem using Okhttputils2 with Android 10

Ivan Leal

Member
Licensed User
Longtime User
Hello guys,

I use okhttputils2 to send requests to my webservice. When I compiled an app to run under Android 10, I received the following error when sending an HTTP request:


Error occurred on line: 188 (HttpJob)
java.lang.IllegalArgumentException: unexpected url: /executaquerycondor.php?Query=INSERT+INTO+requisicoesronda%28TipoSolicitacao%2C+StatusRequisicao%2C+CNPJ%2C+DataSolicitacao%2C+SmartID%2C+SmartToken%29+VALUES%28QMARK10QMARK%2C+QMARK0QMARK%2C+QMARK00.151.754BARRA0001-42QMARK%2C+QMARK13BARRA12BARRA2019+13%3A40%3A48QMARK%2C+QMARKc2a29353ef03580bQMARK%2C+QMARKdVHdk9VN_xQ%3AAPA91bFfnc7YJBiHRzL5GHKddQrpQhn_ZeFo9lKvlbmNpIo-GaOf17gatFE9KCPseeXCkM1lJ6vAOk-_3o6-RjYIbyqw1NOsK8VfmIbw5X5Nsx6F067rxP_PqDWZEV1NDbTcqKxmEtjRQMARK%29
at okhttp3.Request$Builder.url(Request.java:142)
at anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.InitializeGet(OkHttpClientWrapper.java:392)
at com.condor.mobile.httpjob._download2(httpjob.java:102)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:220)
at android.app.ActivityThread.main(ActivityThread.java:6929)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)


This app runs normally on all previous Android versions.
I followed all procedures for upgrading the development environment (SDK, Manifest and Jetifier).

OkHttpUtils version is 2.90.

My Manifest:


AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
AddManifestText(
AddPermission(android.permission.PERMISSION_ACCESS_FINE_LOCATION
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
'************ Google Play Services Base ************
AddApplicationText(
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:exported="false"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************
AddApplicationText(
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxxxx"/>
)
AddApplicationText(
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
)
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
SetApplicationAttribute(android:largeHeap,"true")


Please, has anyone had this problem?

 

drgottjr

Expert
Licensed User
Longtime User
/executaquerycondor.php this is a url? isn't condor some type of monitor of resources running on some server somewhere? where is that somewhere in this case?

leave, for the moment, the legality of the rest of your get request. have you copied and pasted the url (as shown above) in a regular browser? doesn't work here...
 
Upvote 0

Ivan Leal

Member
Licensed User
Longtime User
executaquerycondor.php is a PHP routine that sends the request to the MySQL database. The whole app is working normally on all Android versions except version 10.

Looking at the error message, I came to the conclusion that the problem may be in the OkHttpUtils library or something missing to update in my development environment. I tested on two devices under Android 10 and the same error occurred.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
http is no longer supported by default. you have to enable it in the manifest. did you? i can't find the setting in my notes. maybe someone else will point you. or i'll rever if i find it
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
- 28 - Non-ssl (non-https) communication is not permitted by default. It can be enabled in B4A v9+ by adding this line to the manifest editor:


CreateResourceFromFile(Macro, Core.NetworkClearText)
 
Upvote 0

Ivan Leal

Member
Licensed User
Longtime User
Ok. Thanks a lot drgottjr.

I found the cause of the problem.

In fact, my HTTP access address is dynamic and is stored in a hosted text file. The problem is when I run the HttpJob.Download method to read this file. The protocol is plan FTP (no security policies) and I don't know why Android 10 is not downloading this file.

I added your suggestion to the manifest, but it still didn't work.


If you have more suggestions, thank you in advance.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i can run it "successfully"* on desktop browser, on android 8 and on android 10 (pixel 3a, with modified manifest, sdk 28 and 29)

* - no error, but empty message from server. definitely, nothing like what you get. (btw, using okhttputils2 2.90)
 
Upvote 0

Jorge M A

Well-Known Member
Licensed User
As requested in several posts, please do not write in bold. It would seem that you are screaming. Thank you.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
so i ran a test again (android 10) and captured the headers sent by the server:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
HttpClient1_ResponseSuccess
TaskId: 1
** Headers **
key: content-type value: [text/html]
key: date value: [Sun, 15 Dec 2019 16:33:07 GMT]
key: server value: [Microsoft-IIS/7.5]
key: vary value: [Accept-Encoding]
key: x-powered-by value: [PHP/5.3.13, ASP.NET]
GOT:
** Activity (main) Pause, UserClosed = true **

it claims it's sending html back, but i think some headers are missing. (it's been a while since i had an interest in http headers). there should be, among others, a size of the data returned. so i ran the url with chrome on the desktop and received the same headers as shown above, but with others, including these: gzip encoding and a size of 125 bytes.

i have an app that uses http to download a zip archive, so i'll plug the archiver lib into my test and see if i can get the download that way. even if the payload is a zipped file, the getString call should at least be able to show some garbage in the log. instead all i'm getting so far is an empty "GOT: " ... where something should go.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
if i use this:
B4X:
        Dim in As InputStream = wjob.GetInputStream
        Log("bytes available: " & in.BytesAvailable)
instead of the usual getString call, i get 3 bytes. they don't appear to be zipped (the archiver cannot unzip them), they don't display as strings. they seem to be unsigned ints (they display as negatives unless converted to unsigned), and, even then don't seem to be an acknowledgment by the server. i'll probably check out at this point. sorry
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i also tried it on my unix system. status 200, same 3 bytes as yesterday: \xef\xbb\xbf.
okhttputils has been the same for a couple years now. the so-called "library" version is still available in the original b4a classes and is a just a tidy compilation of those 2 files. every once in a while you'll see a post from erel saying we can still use the classes if we have to. that's how i was able to capture the response headers. they aren't exposed in the compiled version. my unix provider isn't using okhttputils, so you can probably move on to your other option.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Running it without problems on Android 10 like many others. All my webservices work (php, MySQL, etc.). Must be something in your code. Not using SSL is a huge problem for data security.

What kind of webservice do you use?

Do a little demo project (just the OKHttpUtils Job which fails) and upload it. Then we see.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
@KMatle, you ran the url? what exactly did you get as a response?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
this problem - whatever it may be - has nothing to do with okhttputils2.

my apps at the play store use okhttputils. i test on devices running android 5, 8 and 10. at the very least it
is in my interest to take note of any posting in the forum dealing with problems concerning
httputils, especially as relates to android 10. i prefer to learn about someting that might bite me before it
does bite me.

in this case, something did not sound right, so i engaged. i think it is pretty clear at this point that httputils is
not involved. i say that because i have queried the url provided using:
1) okhttuptils with b4a under android 5, 8 and 10,
2) windows 10 with the latest chrome browser,
3) curl under a unix variant which is not running the java net library (the library that okhttupils is the front end for).

they all report the same response: code 200 (ok), and a very small reponse payload consisting of the
BOM 3-byte signature.

clearly, if 2 out of the 3 systems are not running okhttupils and they get the same response as a system that is
using okhttutils, okhttputils is not odd man out.

the query's url appears to be valid. that is, the server answers requests.

the actual get parameters may or may not be valid. depending on how the server is configured, it may or
may not report an error. sometimes, the less said, the better. in the old days, we would send such
requests to /dev/null (after logging, of course). if you tell a bad guy he's sent something illegal and where
he made the mistake, he'll just fiddle with the request and try again. if you say nothing, he'll probably move on.
a less security-minded server might supply more information than it should, thinking it was being helpful.
this is why some servers do not respond to pings.

so, the url provided was an sql insert statement, which should have returned an OK (assuming it was OK).
an insert statement isn't expected to return much.

so i decided to try 3 things:
1) i simply queried the server (on port 8080) with no parameters. please see the error message below.
2) i made up a dummy sql select query using the same table that was referenced in the url.
3) i made up a dummy sql select query using an invented table (presumably invented. i invented it, but it
may have actually existed)

instead of:
B4X:
   insert into requisicoesronda ...

i did:
B4X:
   select * from requisicoesronda

and later:
B4X:
   select * from harry

the response? for what should be legal queries: status 200 (OK) and the 3 bytes (which don't mean OK, btw).
in other words, the same response either way.

for the query referencing a non-existent table harry, i got:

"SELECT * FROM harry\nTable 'condormobile.harry' doesn't exist"

so, if you put no parameters or you put bad parameters, you get a legitimate error message
(which tells me a lot about the server, more than it should have. had i been a hacker, knowing that i was
dealing with a windows box would have saved me a lot of trouble.)

but if you put what should be valid parameters, you get nothing (except status 200 and the BOM signature). so the issue is elsewhere, nothing to do with
httputils.
 

Attachments

  • empty.png
    empty.png
    8.5 KB · Views: 143
  • harry.png
    harry.png
    8.5 KB · Views: 142
Upvote 0

Ivan Leal

Member
Licensed User
Longtime User
Thank you KMatle. In fact, not using SSL is a serious security issue, but the project is still under development and I'm using temporary hosting for testing purposes only.
My webservice is a regular Linux / PHP / MySQL.

I agree with you drgottjr, the problem has nothing to do with okhttputils2. My app composes the URL based on a hosted text file. Periodically, it downloads this file and reads its contents. This is a simple mechanism that allows me to freely change webservice hosting without having to update the entire application.

For it to work properly, the app must be able to download the text file from any FTP server (using FTP, SFTP, and FTPS protocols). I hosted webservice on a virtual server on Google Cloud (Apache, PHP, MySql and FTP server under FTPS protocol) and tested the app. The download was done correctly and the whole engine worked perfectly.

So, I suppose there is some problem with the original testing hosting. I would like to dig deeper to find out why, but just as I am running out of time, I believe you too, I will forget about problematic hosting for now.

I would like to thank you for your time and dedication to my problem. I'll have that as a reference. Thanks to you too, Erel.
 
Upvote 0
Top