Android Question How can i poststring with parameters

Makumbi

Well-Known Member
Licensed User
Please help how can i post this URL with with Parameters and then get the Json returned values
B4X:
Dim Subscriptiondetailsm As Map
    Subscriptiondetailsm.Initialize
    Subscriptiondetailsm.put("account","098866")
    Subscriptiondetailsm.put("Phone","0782911364")
   
    Dim json As JSONGenerator
    json.Initialize(Subscriptiondetailsm)
    Dim contentr As String = json.ToString
    'Depends on okHttputils library
    Dim clientb As HttpJob
    clientb.Initialize("",Me)
    clientb.PostString("http://192.168.1.205/KABOJJAAPPAPI/API/RecieveSMS",contentr)
    clientb.GetRequest.SetContentType("application/json")    'set the header as json
    clientb.GetRequest.SetContentEncoding("UTF8")
           
    Wait For Jobdone(clientb As HttpJob)
   
    If clientb.Success Then
        Dim Resultd As String = clientb.GetString
        Dim data As JSONParser
        data.Initialize(Resultd)
        '
        'Dim product As Map = data.NextObject
    End If
below is the URL i wanted to use to post and return the values please help
B4X:
http://localhost:5216/KABOJJAAPPAPI/api/HandlerVBLoadterm/GetCustomersJSON/0782911364/Father
 

Makumbi

Well-Known Member
Licensed User
Note that you are not using HttpJob correctly.
[B4X] OkHttpUtils2 with Wait For

It will be easier to help if you post the response: Log(Resultd)

B4X:
    Dim Subscriptiondetailsm As Map
    Subscriptiondetailsm.Initialize
    Subscriptiondetailsm.put("account","Father")
    Subscriptiondetailsm.put("Phone","0782911364")

    Dim json As JSONGenerator
    json.Initialize(Subscriptiondetailsm)
    Dim contentr As String = json.ToString
    'Depends on okHttputils library
    Dim clientb As HttpJob
    clientb.Initialize("",Me)
    clientb.PostString("http://192.168.1.205/KABOJJAAPPAPI/api/HandlerVBLoadterm/GetCustomersJSON/0782911364/Father",contentr)
    clientb.GetRequest.SetContentType("application/json")    'set the header as json
    clientb.GetRequest.SetContentEncoding("UTF8")
        
    Wait For Jobdone(clientb As HttpJob)

    If clientb.Success Then
        Dim Resultd As String = clientb.GetString
        Dim data As JSONParser
        data.Initialize(Resultd)
        Log(Resultd)
        'Dim product As Map = data.NextObject
        Else
        Log(Resultd)
    End If

at the error log
iam getting
B4X:
Error evaluating expression.
Note that
0782911364 and Father are parameters to be passed
i have looked at ERel 's example but it is not clear
B4X:
Sub DownloadQuote
   Dim j As HttpJob
   j.Initialize("", Me) 'name is empty as it is no longer needed
   j.Download("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand")
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
     'The result is a json string. We parse it and log the fields.
     Dim jp As JSONParser
     jp.Initialize(j.GetString)
     Dim quotes As List = jp.NextArray
     For Each quot As Map In quotes
       Log("Title: " & quot.Get("title"))
       Log("Content: " & quot.Get("content"))
     Next
   End If
   j.Release
End Sub
 
Last edited:
Upvote 0
Top