B4J Question HttpJob in Server Handle

sgt

Member
Licensed User
Longtime User
Hi
I am having an issue running a HttpJob in a Server Handle when in release mode running on multi thread mode, single threaded mode and debug work seem to be ok. The issue is I set a Authorization token on the header object of the job.GetRequest to authenticate with a external API and what seems randomly the header information is lost along with the authorization token making the call to fail. I have used a network sniffer to see the calls between my server and the external api server and the calls that fail have the header that I set missing. Is there something you need to do differently for these calls in handler for the multi thread. The code is below, I am using the message loop to wait for the job to complete before finishing the handler.

B4X:
        Dim j As HttpJob
        j.Initialize("",Me)
        j.PostString($"${fnlServer}/xxxx/GetDocUploadList"$, payload)
        j.GetRequest.SetContentType("application/json")
        j.GetRequest.SetHeader("Authorization", "Bearer " & access_token)
        
        wait for (j) JobDone(j As HttpJob)
        If j.Success Then
            Dim response As String = j.GetString
            ....
        Else
            Log(j.ErrorMessage)
        End If

Below is the header information that is missing on failed call and a call where the data is correct.
Headers2.png

Headers1.png


Any help appreciated
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
. Is there something you need to do differently for these calls in handler for the multi thread.
No nothing.

i think the issue could be in another part, there are cookies and in your code you are not setting any cookie. the code you are presenting is okey, may be you need to zoom out a bit more.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

sgt

Member
Licensed User
Longtime User
Thanks for your replies, I am using the server version of OKHttpUtils2 by setting the SERVER in the Conditional Symbols and it tells me it has set to server mode when the server starts. I am also using the StartMessageLoop to wait for the httpJob to complete and StopMessageLoop to continue processing the handle request. It does seem to be an issue when running the handler on the main thread or not. If I set the srvr.AddHandler("/reqdocuments", "DocRequestHandler", True) I don't get any issues but setting srvr.AddHandler("/reqdocuments", "DocRequestHandler", False) I get the issue of the header not being set intermittently.

BTW a good tool to see what is happening on the network and simple to use compared with others is 'HTML Toolkit' found here
 
Last edited:
Upvote 0
Top