• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps how to submit

ezekel

Newbie
Hi,

I have 2 EditText Field, how can i pass my data to my server in localhost when the button is click,I already know how to use button click,but the problem is i don't know how to pass the value.?

by the way in my php script when the data is pass by the android is it the same way in checking the parameters by using iset() ?.


Thank you in advance.
 
Pass by $_GET or $_POST, the same as any wen interface. isset() will work the same way, no matter what passes the variables.
 
Hi Rukbat,

THank you for the quick reply...can i ask how can i connect to my localhost so that i can pass my data to the localhost...what APi of org.apatche that i will use?

THank you in advance.
 
...how can i connect to my localhost so that i can pass my data to the localhost...
Try something like the one below. It will open HTTP connection to localhost (provide exact URL to your php script) and send POST request along with "your_data" string:
Code:
HttpURLConnection con = (HttpURLConnection) new URL("http://127.0.0.1").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
OutputStream reqStream = con.getOutputStream();
reqStream.write("your_data".getBytes());
 
Hi surlac,

Thank you for the reply...I am confuse for this "reqStream.write("your_data".getBytes());" what is the format of "your_data"?...you mean like this,...reqStream.write("name:mytestname".getBytes());..?

please correct me if i am wrong.

Thank you.
 
Try something like the one below. It will open HTTP connection to localhost (provide exact URL to your php script) and send POST request along with "your_data" string:
Code:
HttpURLConnection con = (HttpURLConnection) new URL("http://127.0.0.1").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
OutputStream reqStream = con.getOutputStream();
reqStream.write("your_data".getBytes());


By the way is it possible to return message back to my android phone then show some toast ?example message...success or invalid username and password..something like that.


Thank you in advance.
 
I am confuse for this "reqStream.write("your_data".getBytes());" what is the format of "your_data"?...
"your_data" is a Serializable object, which you're able to reconstruct on the server. Default platform charset will be used in case of String.
 
By the way is it possible to return message back to my android phone then show some toast ?
Sure. Socket is still open, listen to the response like this:

Code:
InputStream resStream = con.getInputStream();
int len = resStream.read(byteBuf);
 
"your_data" is a Serializable object, which you're able to reconstruct on the server. Default platform charset will be used in case of String.


Hi surlac!, I could not get the idea of "serializable object" ...


reqStream.write("fname:myfirsttextfield,pwd:mysecondtextfield".getBytes());..is this what you mean?

please correct me if i am wrong.

Thank you.
 
Try something like the one below. It will open HTTP connection to localhost (provide exact URL to your php script) and send POST request along with "your_data" string:
Code:
HttpURLConnection con = (HttpURLConnection) new URL("http://127.0.0.1").openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
OutputStream reqStream = con.getOutputStream();
reqStream.write("your_data".getBytes());

I have error in logcat

Error opening trace file: No such file or directory (2)

this is the url HttpURLConnection con = (HttpURLConnection) new URL("http://127.0.0.1/mytest/login.php").openConnection();


please i need your help.

Thank you in advance.
 
Back
Top Bottom