Android Question [SOLVED] get POST parameters on HttpServer

sirjo66

Well-Known Member
Licensed User
Longtime User
Hi,
in my app I have an HttpServer
B4X:
Private server As HttpServer
in event HandleRequest I need to read the parameters, and I use this code
B4X:
        Log("Mtd: " & Request.Method)
        Log("URI: " & Request.RequestURI) 'handle the request based on the URL
        Log("Cell: " & Request.GetParameter("cell"))
        Log("Text: " & Request.GetParameter("testo"))
This work very well if I call it with GET method, but if I call it with POST method I don't read any parameter

How can I read POST parameters ?
I make POST call with "multipart/form-data" content type.

If I call my server http with a normal browser (for example Firefox) and an HTML page, it works.
If I call my server http with .NET program (with WebRequest object or WebBrowser object) it don't works.
.NET code is correct, if I try to call others POST server, the answer is correct, it tell me what is the parameters and it is ok

Thanks
Sergio
 
Solution
SOLVED

I changed .NET code.
Now I don't use WebRequest object (that it needs to build the request step by step) but I use HttpClient object, and it works

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Previous to the post that I have indicated there is another one that reads the entire header, try it.

Is it possible that the parameters it sends are not found in the header but in the body?
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Previous to the post that I have indicated there is another one that reads the entire header, try it.

Is it possible that the parameters it sends are not found in the header but in the body?

I tried it but don't works.

Yes, I think that the parameters are in the body, I build myself the call, using boundary, and
Content-Disposition: form-data; name="paramName" "paramValue"
and so on.
This is because I need also to send a file.
If I try this call with some site for to test the call (for example http://httpbin.org/post) it works, it show me the parameters call and it is correct.

As I wrote, if I try to call it by Firefox or Chrome (with an HTML page), it works.
Is there a simple method for to sniffer what browser send ?

EDIT: I will try it with postman program
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
if they are in the body then these parameters will always return empty
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
SOLVED

I changed .NET code.
Now I don't use WebRequest object (that it needs to build the request step by step) but I use HttpClient object, and it works
 
Upvote 0
Solution
Top