Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

1 solution

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):

Java
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");
	}
	is.close();
			
	Log.d("Server response", sb.toString());
} catch (Exception e) {
	Log.e("Error", "Error converting result " + e.toString(), e);
}
</namevaluepair></namevaluepair>


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[^]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900