Android Question get the POST content??

ilan

Expert
Licensed User
Longtime User
hi, i am trying to send from my b4a app strings to a JRDC server.
how do i get the content back in the RDCHandler - Handle event?

this is my POST send code:

B4X:
    Dim j As HttpJob
    j.Initialize("dbrequest",Me)
    j.Tag = "job1"
    j.PostString(rdcLink & "?method=" & method ,"abc")

Handle event:

B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
     '????
End Sub

thanx
 
Last edited:

ilan

Expert
Licensed User
Longtime User
thank you erel for your answer.

so the post request should look like this:

B4X:
    Dim j As HttpJob
    j.Initialize("dbrequest",Me)
    j.Tag = "job1"
    j.PostString(rdcLink & "?method=" & method ,"abc")
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log("Inserted successfully!")
    End If
    j.Release

but i didnot understood you answer:

RDCHandler already reads the POST payload. See its code.

do you mean from the req.InputStream ?

thank you
 
Upvote 0

ilan

Expert
Licensed User
Longtime User

thanx erel,

so i managed already to convert a map to byte send it with *.postbyte() and convert it back to a map from the req. InputStream.

but if i send a string i have read somewhere that http already converts it to a byte object so i tought converting it back to string but i am getting an error.
i solved it using a different approach.

i append the string to the post url instead and then i am able to get the string back. is this the right way to do?

B4X:
    Dim s As String = "abc"
    j.PostString(rdcLink & "?method=" & method & $"& data=${s}"$,"")

thanx
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
req.InputStream will work with PostString. You just need to add BytesToString to convert the array of bytes to a string. Use UTF8 encoding.

ok thank you, i will try and if i get an error i will post the exact error + example project here.

thanx :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
you were right erel. thank you for your support :)

relevant code (if someone may need):

B4X:
            Dim buffer() As Byte = Bit.InputStreamToBytes(in)
            Dim s As String = BytesToString(buffer, 0, buffer.Length, "UTF-8")
            Log(s)
 
Upvote 0
Top