Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android HTTP Connection refused

Tags:

android

http

I am trying to access from an Android device over WiFi a local web server which I can access from my laptop either on the browser, or using curl. I can also access the server on the android device browser.

The code I am using to access the server yields a "connection refused" exception.

This is the code:

public void getController1() {
  HttpClient httpclient = new DefaultHttpClient();
  HttpGet httpget = new HttpGet("http://192.168.1.169:8000");
  HttpResponse response = null;
  System.out.println(httpget.toString());
  try {
    response= httpclient.execute(httpget);
    txtViewStatus.setText("Controller 1 - OK"+response);
  } catch(Exception e) {
    e.printStackTrace();
    txtViewStatus.setText("Controller 1 - Error"+e);
  }
}
like image 890
Tori Avatar asked Feb 27 '12 17:02

Tori


4 Answers

Problem solved. The issue was a corrupted manifest file. I deleted the permission lines and re-typed them in and now the problem is gone

like image 115
Tori Avatar answered Oct 26 '22 13:10

Tori


I was missing permission; you should check manifest file

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
 <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>    
 <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
like image 43
DPP Avatar answered Oct 26 '22 14:10

DPP


Check your internet connection strength.

For my case the network connection is low so this error thrown.

like image 42
Sampath Kumar Avatar answered Oct 26 '22 15:10

Sampath Kumar


Past this to your manifest file:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
like image 37
r-magalhaes Avatar answered Oct 26 '22 14:10

r-magalhaes