B4J Question OkHttpUtils in Server handler.

jahswant

Well-Known Member
Licensed User
Longtime User
Do I need something specia to make HTTP requests in a server handler ? I'm getting an error code ResponseError. Reason: Unauthorized, Response: when in server while this code works very well in a B4XPage Application.

I even followed this tutorial https://www.b4x.com/android/forum/threads/server-jokhttputils2-server-version.124350/ always get error code ResponseError. Reason: Unauthorized, Response: when in server handler.
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

jahswant

Well-Known Member
Licensed User
Longtime User
It doesn't matter whether it is a server app or not. Maybe you added HU2_ACCEPTALL to the other app?
I’m not using any build configuration in any of the apps. I will zip the working project and send it to you because it contains my credentials. Then you’ll see yourself.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Don't forget to configure server mode: https://www.b4x.com/android/forum/threads/okhttputils-in-server-handler.135544/
2. Don't forget to release jobs.

I see the issue you describe. It looks like the first request fails for some reason.
Implement a retry mechanism:

B4X:
    Dim Success As Boolean =  False
    For retries = 1 To 5
        Dim j As HttpJob
        j.Initialize("",Me)
      '''
        wait for (j) JobDone(job As HttpJob)
        Success = Job.Success
        j.Release
        If Success Then
            Exit
        Else
            Sleep(500)
        End If
    Next
    Log("RequestToPay: " & Success)
    Return Success
 
Upvote 0
Top