How to access a remote php file from ANDROID?

By | January 19, 2011

For working on the localhost use and for remote use the IP or domain name of the server.
The following code does this.

package com.pack;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.Bundle;
import android.widget.Toast;

public class active extends Activity
    HttpPost httpPost;
    ResponseHandler response;
    String result;
    HttpClient htClient;

    public void onCreate(Bundle savedInstanceState)

        Toast.makeText(active.this,"Accessing.....", Toast.LENGTH_SHORT).show();

        htClient = new DefaultHttpClient();
        httpPost = new HttpPost("");
 response = new BasicResponseHandler();
 result = htClient.execute(httpPost,response);
 Toast.makeText(active.this,result, Toast.LENGTH_SHORT).show();
 catch (ClientProtocolException e) {

 Toast.makeText(active.this,e.getMessage(), Toast.LENGTH_SHORT).show();
 catch (IOException e) {
 Toast.makeText(active.this,"IO Error " + e.getMessage(), Toast.LENGTH_LONG).show();

3 thoughts on “How to access a remote php file from ANDROID?

  1. Simple PHP

    You’ve got great insights about PHP systems, keep up the good work!


Leave a Reply

Your email address will not be published.