Click here to Skip to main content
13,143,459 members (30,820 online)
Rate this:
Please Sign up or sign in to vote.
Hi, I develop one android application in that i have one login and registration form in that name, password, email, phno that are the field. which fill up bye the user. When they fill registration form then data will be store in the remote server using php script. And after that Name and password will be use to login.

i am new to web service in android so please help me to find this....
Thanks & Regards....
Posted 26-Jul-12 19:18pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The simplest answer would be to call the PHP script on the server, and submit the parameters to it via a GET for instance (although NOT recommended, as being a reg form, there will most likely be private information).

If you want to do it properly, you should open an encrypted (HTTPS) connection from your Android application to the server, and submit the registration info securely. Now, I have no HTTPS example to give you at the moment, but I can show you a simple way of POSTing data to your script's url (unsecurely):

String result = null;
InputStream is = null;
String url = "http://localhost/your_php_script_url.php";
//Create the request parameters that will be sent to the server
ArrayList<namevaluepair> params = new ArrayList<namevaluepair>();
params.add(new BasicNameValuePair("param1_name", "param1_value"));
params.add(new BasicNameValuePair("param2_name", "param2_value"));
params.add(new BasicNameValuePair("param2_name", "param2_value"));
//Execute the HTTP POST and get the response as an InputStream
try {
	HttpClient httpclient = new DefaultHttpClient();
	HttpPost httppost = new HttpPost(url);
	httppost.setEntity(new UrlEncodedFormEntity(params));
	HttpResponse response = httpclient.execute(httppost);
	HttpEntity entity = response.getEntity();
	is = entity.getContent();
} catch (Exception e) {
	Log.e("Error", "Error in http connection " + e.toString(), e);
//Convert response to String and output it to Android console
try {
	BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
	StringBuilder sb = new StringBuilder();
	String line = null;
	while ((line = reader.readLine()) != null) {
		sb.append(line + "\n");
	Log.d("Server response", sb.toString());
} catch (Exception e) {
	Log.e("Error", "Error converting result " + e.toString(), e);

This example uses the default Apache HTTP library found in Android. Just replace the mock parameters and variables with what you need in the script, and should be good to go

Also, this is not a webservice per se (although it could be argued that it's done RESTfully). If you need to call a proper webservice (eg SOAP), well, just Google it. Here it is[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 27 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100