Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android WebService
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 20:18pm

1 solution

Rate this: bad
good
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");
	}
	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[^]
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 335
1 OriginalGriff 250
2 Kornfeld Eliyahu Peter 130
3 DamithSL 120
4 Peter Leow 95
0 OriginalGriff 7,355
1 DamithSL 5,199
2 Sergey Alexandrovich Kryukov 4,942
3 Maciej Los 4,906
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 27 Jul 2012
Copyright © CodeProject, 1999-2014
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