Android Question HttpJob GetRequest Duplicated

Jose Cuevas

Member
Licensed User
Longtime User
Hi, I am consuming an REST API by 4G cellular connection, but when the connection is poor, they tell me that the API reports a double Request (I am not the owner of the API, it is third-party). If the connection is strong, it does not duplicate the Request.

Has anyone experienced this failure?

This is the Code:

B4X:
Sub API
    
    Try
        Dim XJob As HttpJob
        Dim XML As String
        Dim sJSON As String
        
        XML = "XML Content......"
        
        XJob.Initialize("FEL", Me)
        XJob.PostString("https://api.com.gt/res", XML) 
        XJob.GetRequest.SetContentType("application/xml")
        XJob.GetRequest.SetHeader("ID", "001")
        XJob.GetRequest.SetHeader("KeyApi","3406D1A2CEBA15C02D37CD5A060A573")
        XJob.GetRequest.Timeout = 6000

        Wait For (XJob) JobDone(XJob As HttpJob)

        If XJob.Success Then
            sJSON = XJob.GetString       
        Else
            Log("XJobError: " & XJob.ErrorMessage.Trim)
        End If

        XJob.Release
                
    Catch
        Log(LastException)
        
    End Try

I will appreciate any help you can give me.

Regards
 

drgottjr

Expert
Licensed User
Longtime User
it is in the nature of tcp (and, therefore, the underlying okhttp3 api) to retry until it gets an
acknowledgment or to hang up either after a certain time or a certain number of failures.

if your device does not receive the expected acknowledgment, it will try again (silently).
if you search online for okhttp3 (what okhttputils2 is based on), you will see the matter is
an ongoing topic of discussion. you would need to write your own okhttp3 client to modify
this (which, in any case, is discouraged). the whole intent of tcp is to do everything
possible to guarantee faithful transmission of the request. a poor network connection
would interfere with this.
 
Upvote 0
Top