1

i tried to connect to my external database but i have an error and i don't know why, here is my code

try{
        String link = "http://127.0.0.1/Myfile.php";
        //HttpClient httpclient = new DefaultHttpClient();
        URL url=new URL(link);
        //HttpPost httppost = new HttpPost(link); //YOUR PHP SCRIPT ADDRESS
// HttpPost httppost = new HttpPost("http://172.23.193.32/elift-test/myfile.php"); //YOUR PHP SCRIPT ADDRESS
        HttpURLConnection response = (HttpURLConnection) url.openConnection();
        response.connect();
        //isr = response.getInputStream();
    }
    catch(Exception e){
        Log.e("log_tag", "Error in http connection "+e.toString());
        resultView.setText("Couldnt connect to database");
    }
  • you have to host your server this "http://127.0.0.1/Myfile.php" address seem to be your local machine address its not accessible from mobile devices. – Ando Masahashi Apr 02 '15 at 16:12
  • You are using 127.0.0.1 as localhost which is not a localhost for android see this link [http://stackoverflow.com/a/9759714/2715073](http://stackoverflow.com/a/9759714/2715073) – Pankaj Apr 02 '15 at 16:14

0 Answers0