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:
this is how i read it:
it does work, i get the JSON string and i can convert it back to a JSON object but is this the right way?
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?