B4J Question Read POST request??

ilan

Expert
Licensed User
Longtime User
hi

i would like to know what is the proper way to read a POST request in b4j Server App?

this is the Post request:

B4X:
Private Sub addNewUser
    Dim j As HttpJob
    j.Initialize("", Me)
    Dim json As JSONGenerator
    json.Initialize(CreateMap("name":"ilan","adress":"israel","phone":"0501234567"))
    j.PostString($"${api_url}/add-user-quiz"$,json.ToPrettyString(0))
    j.GetRequest.SetHeader("api-key",api_key)  
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release
End Sub

this is how i read it:

B4X:
    if req.Method.ToUpperCase = "POST" Then
         Dim data() As Byte = Bit.InputStreamToBytes(req.InputStream)
        Log(BytesToString(data, 0, data.Length, "UTF-8"))
    End If

it does work, i get the JSON string and i can convert it back to a JSON object but is this the right way?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top