YosiFZ
YosiFZ

Reputation: 7900

HttpClient.execute always gives Exception

I tried to bring HTML of a web and i use this code for doing this :

HttpClient httpClient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpGet httpGet = new HttpGet("http://www.google.com");
    HttpResponse response;
    try {
        response = httpClient.execute(httpGet, localContext);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

and always in the response = httpClient.execute(httpGet, localContext); it give me exception, also in other codes that i tried

Upvotes: 1

Views: 5934

Answers (1)

Wroclai
Wroclai

Reputation: 26925

Have you tried setting the INTERNET permission in the manifest file?

Sample code:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="sample.hello"
  android:versionCode="1"
  android:versionName="1.0">

<!--- Here is where you put your permissions. --->
<uses-permission android:name="android.permission.INTERNET" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".HelloWorld"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
</manifest>  

Upvotes: 6

Related Questions