Reputation: 1
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
client.execute(request);//it fails at this line
Log.e("yo", "yo");
} catch (Exception e) {}
Have anyone figured out the problem please as I am experiencing the same issue. My device is connected to the same network, pasting the URL in browser works however using HTTP doesn't.
Upvotes: 0
Views: 251
Reputation: 4140
try HttpPost method
Declare INTERNET PERMISSION IN manfiest file
httpclient=new DefaultHttpClient();
HttpPost httppost=new HttpPost(URL);
HttpResponse res = null;
try {
res = httpclient.execute(httppost);
System.out.println("asa "+res);
} catch (ClientProtocolException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
Upvotes: 1
Reputation: 3875
Are you running it on the same thread as your UI? You have to use separate thread for any network connection to prevent UI Blocking. You need to use AsyncTask in this case; and obviously, android Internet permission is needed.
Upvotes: 0
Reputation: 638
Did you forget to add
<uses-permission android:name="android.permission.INTERNET" />
to your AndroidManifest.xml?
Upvotes: 0