Android Question Http Job and Request Listener

catyinwong

Active Member
Licensed User
Longtime User
I refer to the following post:

I am wondering how to read whatever is posted from the http job through the received ServletRequest.

So far I can only read header and url from the request. Where can I find the data from a http.poststring / http.postbytes method?
 
Where can I find the data from a http.poststring / http.postbytes method?
Try :
B4X:
Dim In As InputStream = req.InputStream
Check this tutorial.
 
Upvote 0
B4X:
'prints the requests parameters
Public Sub PrintAllParameters (req As ServletRequest) As String
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("<ul>")
    Dim params As Map = req.ParameterMap
    For Each name As String In params.Keys
        sb.Append("<li>").Append(name).Append(":")
        Dim values() As String = params.Get(name)
        For Each value As String In values
            sb.Append(" ").Append(value)
        Next
        sb.Append("</li>")
    Next
    sb.Append("</ul>")
    Return sb.ToString
End Sub

This is from an b4j example found in the forum. It is using jserver.

I don´t know whether it works with b4a httpserver.
 
Last edited:
Upvote 0
Try :
B4X:
Dim In As InputStream = req.InputStream
Check this tutorial.

That works only on B4J. In the B4A library for http server, the req does not have the "inputstream" extension. ?
 
Upvote 0
B4X:
'prints the requests parameters
Public Sub PrintAllParameters (req As ServletRequest) As String
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("<ul>")
    Dim params As Map = req.ParameterMap
    For Each name As String In params.Keys
        sb.Append("<li>").Append(name).Append(":")
        Dim values() As String = params.Get(name)
        For Each value As String In values
            sb.Append(" ").Append(value)
        Next
        sb.Append("</li>")
    Next
    sb.Append("</ul>")
    Return sb.ToString
End Sub

This is from an b4j example found in the forum. It is using jserver.

I don´t know whether it works with b4a httpserver.

The getparameter method in B4A requires a key and hence only return a single value. No options for getting all names of existing parameters. ? That's why I am wondering what the default names of parameters for the http job are.
 
Upvote 0
Why are you using HttpServer? The only relevant use case is if you want to interact with your app from the browser. There are much better and simpler solutions for general communication.

HttpServer supports two types of requests: GET requests and multipart POST requests. Nothing else.

If you want to build a real http server then switch to B4J.
 
Upvote 0
Why are you using HttpServer? The only relevant use case is if you want to interact with your app from the browser. There are much better and simpler solutions for general communication.

HttpServer supports two types of requests: GET requests and multipart POST requests. Nothing else.

If you want to build a real http server then switch to B4J.

I want to use it for a communication between a group of client mobile apps.
 
Upvote 0
Why are you using HttpServer? The only relevant use case is if you want to interact with your app from the browser. There are much better and simpler solutions for general communication.

HttpServer supports two types of requests: GET requests and multipart POST requests. Nothing else.

If you want to build a real http server then switch to B4J.

Yes I know. but the thing is I dont know how to catch the POST content. I have tested with the library and see that the POST command works on the client app because I can see the change in content length. But there is no commands for reading the content.... So all the POST commands are meaningless because I cant read what is posted
 
Upvote 0
Use Postmultipart instead of poststring.... Poststring is not supported by httpserver as mentioned above.

What is the code to read the content from the request?

From the B4A server I only have
Code:
sub server_handlerequest(request as servletrequest, response as servletresponse)

Methods with servletrequest are:
req.getheader
req.getparameter
req.getuploadedfile
req.method
req.remoteaddress
req.requesturl
 
Upvote 0
As you are the coder you know what you added to the map.

You can get the values by the keys you used to fill the map using req.getparameter i guess. I personally never would use httpserver in my B4A App
so the keys in the map would be the keys for the parameter? < tested. It is what I am looking for! ♡

How about the keys for the list of files?
 
Upvote 0
Did you think over the possiblilities available?
Why not?
What about req.getuploadedfile?
I mean the getuploadedfile need a key to identify the uploaded files, which is a list. so I dont know what the key is meant to be

found the answer. a special type in list. thanks for all the help!
 
Upvote 0
Back
Top