Receive data from PHP server

voted: 0
android receive data post

Easiest way to receive data from PHP server. You can receive data from database on your server by prepared PHP file. In this example you have receiving data from server by POST method. Data called "data" and "data1" are sent to the server and you receive response with your expected data (in this example you receive String value, which is parsed to Integer).

public static int counter() throws ClientProtocolException, IOException {
	int value = 0;
	HttpClient client = new DefaultHttpClient();	
	HttpPost httppost = new HttpPost("http://file.on.server/receive.php");

	List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
	nameValuePairs.add(new BasicNameValuePair("data", "data");
	nameValuePairs.add(new BasicNameValuePair("data1", "data1"));
	HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs);

	ResponseHandler<String> responseHandler = new BasicResponseHandler();

	String response = client.execute(httppost, responseHandler);
	value = Integer.parseInt(response);

	return value;
working url: not entered
version: not entered
Leave a Comment:
Characters left:
No comments yet.