B4J Question [solved] questions around HttpJob and ServletRequest

svanneste

Member
Licensed User
Hi,
I am currently learning B4X so that's not a critical question but I have some questions using data in ServletRequest when sent by a POST from HttpJob, please.

PostString
In fact making a POST, I am able to use the PostMultipart but absolutely not PostString because how do I get the string in the ServletRequest ?

ParameterMap
Should I be able to get a Map using ParameterMap when using PostMultipart or is it only used when a web form sends some data ? Or perhaps I miss a way to send parameters from HttpJob ?

Thanks for your replies.

My libraries versions are :
jOkHttpUtils2 2.93 // jServer 3.00
 

svanneste

Member
Licensed User
OK, I perhaps found a part of the reply :
ParameterMap is used with a GET request and Download2

but I still can't figure how to receive a string sent with PostString.
 

Erel

Administrator
Staff member
Licensed User
PostString and PostBytes let you set the POST payload to whichever value you like. If you want to send parameters using a standard format then use:
B4X:
Sub Test
    Dim j As HttpJob
    j.Initialize("", Me)
    j.PostString("link...", "a=b&a=ccc&mmm=nnnn")
    j.GetRequest.SetContentType("application/x-www-form-urlencoded")
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    End If
    j.Release
End Sub
Handler example:
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim params As Map = req.ParameterMap
    For Each k As String In params.Keys
        Dim p() As String = params.Get(k)
        Dim l As List = p
        resp.Write($"${k}: ${l}
"$)
    Next
End Sub
 
Top