Android Question getstring unknown

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi all,
I'm using Erel routine about multipartpost:
https://www.b4x.com/android/forum/threads/android-http-multipart-requests.8411/#post-47094

B4X:
Sub Process_Globals
    Dim hc As OkHttpClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
        If FirstTime Then
        hc.Initialize("hc")
    End If
        ......
        ......
End Sub

Sub pgcertificatoBTInvia_Click
            'Add files
            Dim files As List
            files.Initialize
            Dim FD As FileData
            FD.Initialize
            FD.Dir = File.DirDefaultExternal
            FD.FileName = nomefilecertificato
            FD.KeyName = "upfilecert"
            FD.ContentType = "application/octet-stream"
            files.Add(FD)

            'Add name / values pairs (parameters)
            Dim NV As Map
            NV.Initialize
            NV.Put("matricola", Main.WFAtletaId)
            NV.Put("id_associazione ", Main.WFStrutturacod)
            NV.Put("nomefile", nomefilecertificato)
            Dim req As HttpRequest
            req = MultipartPost.CreatePostRequest("http://www.example.com/1.php", NV, files)
            hc.Execute(req, 1)
        Else
            messaggio=ML.ML_pgcertificato_msgbox_scegli
            Msgbox2(messaggio, "webfitness","OK","","", LoadBitmap(File.DirAssets, "wflogo.png"))
        End If
end sub

Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
   Log("error: " & Response & " " & StatusCode)
   If Response <> Null Then
       Log(Response.GetString("UTF8"))
       Response.Release
   End If
End Sub
Sub hc_ResponseSuccess (Response As okHttpResponse, TaskId As Int)
   Msgbox(Response.GetString("UTF8"), "")
   Response.Release
End Sub

I just modified OkHttpResponse instead ok OkHttpResponse and okHttpRequest instead of HttpRequest
Also in MultiPartPost module

I have this error: getstring unknown member
upload_2018-4-19_11-24-13.png

I use B4A 7.80
android.jar is version 27
and use these libraries:
upload_2018-4-19_11-26-15.png


Thanks all
Marco
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
'    Dim hc As OkHttpClient 'Not needed
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Not needed
'    If FirstTime Then
'        hc.Initialize("hc")
'    End If
        ......
        ......
End Sub
In pgcertificatoBTInvia_Click replace
B4X:
Dim req As HttpRequest
req = MultipartPost.CreatePostRequest("http://www.example.com/1.php", NV, files)
hc.Execute(req, 1)
with
B4X:
Dim j As HttpJob
j.PostMultipart("http://www.example.com/1.php", NV, files)
Wait for (j) JobDone(Response As HttpJob)
If Response.Success Then ' hc_ResponseSuccess
    Msgbox(Response.GetString, "")
Else ' hc_ResponseError, but without StatusCode
    Log("Error : " & Response.ErrorMessage)
End If
You don't need hc_ResponseError and hc_ResponseSuccess. You need to add the OKHttpUtils2 library to your project.

Watch the video posted at [B4X] OkHttpUtils2 with Wait For
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top