Bug? [solved]Job.GetString fails if called script does not return a response (Job.Success=true)

KMatle

Expert
Licensed User
Longtime User
Using okHttp & HttpUtils, today I called a php script and by mistake I forgot to return a result from the script.

So Job.Success was true but Job.GetString failed with "android.system.ErrnoException: open failed: ENOENT (No such file or directory)" which is "ok" -> Job was ok but there is no result.

Am I blind here? I don't see a way to handle this (except try/catch).
 

DonManfred

Expert
Licensed User
Longtime User
change you php so that it doe return anything. iven if no result found. Return a empty JSON (echo "[]";)
 

KMatle

Expert
Licensed User
Longtime User
Is this php script accessible over the internet?


Of course it was my mistake (of course I return something from my php scripts at any time) but it took me some time to realize what the problem was as Job.Success was true but Job.GetString throwed an exception. To check the "problem" just call an empty php script which returns nothing.

Anyway: It would be great if Job.GetString will then return an empty string instead of throwing an exception (see above).
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tested it with this code and OkHttpUtils2:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim job1 As HttpJob
   job1.Initialize("Job1", Me)
   job1.Download("https://link/you've/sent")
End Sub



Sub JobDone (Job As HttpJob)
   If Job.Success = True Then
     Log($"Result: ${Job.GetString}"$)
   Else
     Log("Error: " & Job.ErrorMessage)
   End If
   Job.Release
End Sub
I don't get any error. It prints: Result:
 
Top