Android Question OkHttpUtils2

Status
Not open for further replies.

Angelo Messina

Active Member
Licensed User
Longtime User
Hi everyone, I'm implementing an app that needs to update a table in a SQLite3 database, and when using okhttputils, the added records are always duplicated. Can you explain the reason? I've attached the code to insert the data.

Code:
 

Angelo Messina

Active Member
Licensed User
Longtime User
where is the code ? :oops:
B4X:
Sub SendPut(Sito As String,n_anno As String, n_mese As String, n_giorno As String, n_kwh As String)

    Dim a As Int = 0   
    If (Vecchio>0 And Vecchio<=Cosa) Then   
        Dim job1 As HttpJob
        Dim requestBody As String
        Dim Id1 As Int = Vecchio
        job1.Initialize("job1", Me)
        Dim kwh As Float = n_kwh
        ' Costruzione del corpo della richiesta
        Dim requestBody As String = $"Id=${Vecchio}&anno=${n_anno}&mese=${n_mese}&giorno=${n_giorno}&kwh=${n_kwh}"$
        Log("PUT requestBody: " & requestBody)
        job1.PostString(Sito,"PUT")
        job1.PutString(Sito, requestBody)
        job1.GetRequest.SetContentType("text/plain")       
        Wait For (job1) JobDone(job1 As HttpJob)
        If job1.Success Then
            Log("✅ Risposta job1: " & job1.GetString)
        Else
            Log("❌ Errore job1: " & job1.ErrorMessage)
        End If
        job1.Release
    Else
        Dim job5 As HttpJob
        Dim requestBody As String
        job5.Initialize("job5", Me)
        Dim kwh As Float = n_kwh
        requestBody = $"anno=${n_anno}&mese=${n_mese}&giorno=${n_giorno}&kwh=${kwh}"$
        Log("POST Richiesta " & requestBody)
        job5.PostString(Sito,"POST")
        ' Costruzione URL completo (se il server accetta parametri nella URL)
        Dim fullUrl As String = Sito & "/" & requestBody
        ' Invio POST con corpo identico ai parametri
        Dim requestBytes1() As Byte = requestBody.GetBytes("UTF8")
        job5.PostBytes(fullUrl, requestBytes1)
        job5.GetRequest.SetContentType("text/plain")   
        Wait For (job5) JobDone(job5 As HttpJob)
        If job5.Success Then
            Log("✅ Risposta job5: " & job5.GetString)
            Return
        Else
            Log("❌ Errore job5: " & job5.ErrorMessage)
        End If
        job5.Release
        Return
    End If
End Sub
 
Upvote 0
Status
Not open for further replies.
Top