iOS Question Httpjob error [SOLVED]

Star-Dust

Expert
Licensed User
Longtime User
I use this function without problems in B4A and B4J .. but it generates an error in B4I (on Wait For)
B4X:
Public Sub ReadSingleResult(Query As String,Field As String) As ResumableSub
    Dim j As HttpJob
    Dim Result As String = ""
      
    j.Initialize("", Me)
    j.Download($"${url}query.php?query=${Query}&Field=${Field}"$)
    Wait For (j) JobDone(j As HttpJob)  <<<<------- ERROR

    'Log(j.GetString)
    If j.Success  Then
          Result=J.GetString
    End If
    Return Result
End Sub

ResumableSub said:
Application_Start
Application_Active
ResponseError: unsupported URL, status code: 0
Unexpected event (missing RaisesSynchronousEvents): AFTER_SLEEP
Error occurred on line: 60 (php_comunicate)
*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
Cosa si Mangia +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
Cosa si Mangia -[B4IShell runMethod:] + 448
Cosa si Mangia -[B4IShell raiseEventImpl:method:args::] + 1648
Cosa si Mangia __40-[B4IShell raiseEventImpl:method:args::]_block_invoke + 36
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 1068
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1964
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 100
UIKitCore UIApplicationMain + 212
Cosa si Mangia main + 124
libdyld.dylib <redacted> + 4
)

Why? Perchè?
 

Star-Dust

Expert
Licensed User
Longtime User
I have replaced the Spaces with% 20 (replace (" ", "%20), Now the error has changed slightly
B4X:
Application_Start
Application_Active
ResponseError: unsupported URL, status code: 0
Error occurred on line: 60 (php_comunicate)
*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  Cosa si Mangia       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  Cosa si Mangia       -[B4IShell runMethod:] + 448
  Cosa si Mangia       -[B4IShell raiseEventImpl:method:args::] + 1648
  Cosa si Mangia       -[B4IShellBI raiseEvent:event:params:] + 1580
  Cosa si Mangia       -[B4IDebugResumableSub resume::] + 356
 Cosa si Mangia       -[B4I checkAndRunWaitForEvent:event:params:] + 552
 Cosa si Mangia       -[B4ICommon CallSubDebug4::::] + 488
 Cosa si Mangia       -[B4ICommon CallSubDebug2::::] + 360
 Cosa si Mangia       -[b4i_httpjob _complete::] + 768
 Cosa si Mangia       -[b4i_httputils2service _completejob::::] + 1288
 Cosa si Mangia       -[b4i_httputils2service _hc_responseerror::::] + 1232
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 Cosa si Mangia       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 Cosa si Mangia       -[B4IShell runMethod:] + 448
 Cosa si Mangia       -[B4IShell raiseEventImpl:method:args::] + 2172
 Cosa si Mangia       -[B4IShellBI raiseEvent:event:params:] + 1580
 Cosa si Mangia       __50-[B4I raiseEventFromDifferentThread:event:params:]_block_invoke + 60
 libdispatch.dylib    <redacted> + 24
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1964
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 100
 UIKitCore            UIApplicationMain + 212
 Cosa si Mangia       main + 124
 libdyld.dylib        <redacted> + 4
)

I Add ATS (App Transport Security) and now is thi
B4X:
Application_Start
Application_Active
Error occurred on line: 285 (HttpJob)
*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  Cosa si Mangia       -[ResumableSub_php_comunicate_ReadSingleResult resume::] + 2240
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  Cosa si Mangia       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
  Cosa si Mangia       -[B4IShell runMethod:] + 448
  Cosa si Mangia       -[B4IShell raiseEventImpl:method:args::] + 2172
  Cosa si Mangia       -[B4IShellBI raiseEvent:event:params:] + 1580
 Cosa si Mangia       -[B4IDelegatableResumableSub resume::] + 380
 Cosa si Mangia       -[B4I checkAndRunWaitForEvent:event:params:] + 552
 Cosa si Mangia       -[B4ICommon CallSubDebug4::::] + 488
 Cosa si Mangia       -[B4ICommon CallSubDebug2::::] + 360
 Cosa si Mangia       -[b4i_httpjob _complete::] + 768
 Cosa si Mangia       -[b4i_httputils2service _completejob::::] + 1288
 Cosa si Mangia       -[b4i_httputils2service _hc_responsesuccess::] + 636
 CoreFoundation       <redacted> + 144
 CoreFoundation       <redacted> + 292
 Cosa si Mangia       +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
 Cosa si Mangia       -[B4IShell runMethod:] + 448
 Cosa si Mangia       -[B4IShell raiseEventImpl:method:args::] + 2172
 Cosa si Mangia       -[B4IShellBI raiseEvent:event:params:] + 1580
 Cosa si Mangia       __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 268
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 92
 libdispatch.dylib    <redacted> + 16
 libdispatch.dylib    <redacted> + 1068
 CoreFoundation       <redacted> + 12
 CoreFoundation       <redacted> + 1964
 CoreFoundation       CFRunLoopRunSpecific + 436
 GraphicsServices     GSEventRunModal + 100
 UIKitCore            UIApplicationMain + 212
 Cosa si Mangia       main + 124
 libdyld.dylib        <redacted> + 4
)
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Actually I always did so without problems (with B4A and B4J), I did not even know about Download2.
But would I solve it?
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Download2 encodes the url parameters. If that is the problem here then it will solve it.
The error also persists with Download2.

I have deselected the iHttpUtils2 library and inserted the HttpJob sources.

I followed the error ... and if I run the program step by step with the debug .. the error does not occur ... if instead I run it in DEBUG mode (but not step by step) or in RELEASE I get an error.

As if it raised the event when the data are not there yet. Maybe I should take a break (Sleep o my dear DoEvent)
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I solved by inserting a pause in the Sub Complete of the HttpJob class of the iHttpUtil2 library.
The pause can not be accomplished with the Sleep because it goes up one level and generates other errors, so I have worked to stop the flow of the program

Unfortunately I can not reveal how I made this break .... just know that it works or almost. Sometimes it still generates an error in debug mode.

B4X:
Public Sub Complete (res1 As HttpResponse)
    Response = res1
    #IF B4I AND DEBUG
        log("PAUSE 300")
       ' .................
       ' .................
       ' .................
    #End If
    CallSub2(target, "JobDone", Me)
End Sub

I lost a whole day of work for this nonsense. :mad:
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I keep having a lot of anomalous errors in DEBUG and it works correctly in RELEASE.

It is not stable.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Ok, but I have to send it in private
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank you, it has been solved, now it works correctly.
 
Upvote 0
Top