Android Question post data to a webpage

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Tormentor

Member
Ok i see thanks.
The thing i need first to send username andxa password to a php page then get access to the next page.
How is best to do that.
Im still in learning process so not fully sure if it is post/get or download with okhttputils2 or use webview there also.

But i also gonna look at the post multipart to
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I want to post a data to a webpage like this.
Http://servername.com/page.php?bla=infofromapp
So a post get command for post a page would be nice.

you can do that if the server accepts something like this:
B4X:
Http://servername.com/page.php?username=bla&password=blabla

or do you normally have to fill out a form with input boxes for username/password and click on a "send" button?

some servers accept both ways. if the first is acceptable, then you don't need to post anything. just do like above. otherwise you need to use okhttputils poststring method.

in either case, however, you need to know exactly how the username and password fields are called (eg, "username", "userid", "userID", "ID"). what is the server expecting those fields to be called? in order to know what the fields are called, you need to look at the webpage's source.

do not forget to take note of any "hidden" fields. they must be included in the request. if you're unfamiliar with webpage forms, you need to look into them.

if a form is involved, okhttputils2 has a poststring method to which you would pass the relevant data, eg,
"username={name}&password={password}&hiddenfield={hiddenfield}".

you then download the server's response as you always do. what you do with that response is unclear since you didn't get into that.
 
Upvote 0

Tormentor

Member
Ok thanks for the input. Im gonna check alittle more.
See what i find out. Webpage dource. I have that here so easy to check.
More input are welcome.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
4 post methods of the HTTPJob:
1582014577942.png


B4X:
pars = "bla=infofromapp&bla2=info2fromapp"   'URL-encoded parameters line
j.PostString("http://servername.com/page.php", pars)

The main task is to create a server script (your page.php) that will receive these POST fields and thire values.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
You will find the sample code in 1st post

It is now easier (and highly recommended) to use okHttpUtils2
 
Upvote 0
Top