Reputation: 8944
I'm getting an IOException
from my code using AndroidHttpClient
. Is there something wrong with the code? The code is thrown whether I use port 80
or port 443
, and with Http Schema http
or https
.
The exception is thrown at client.execute
...it is a UnknownHostException
exception..I'm not sure why. I can hit the service from the browser.
// declare locals
JSONObject joResponse = new JSONObject();
String response = "";
try
{
// prepare to execute
HttpHost target = new HttpHost(hostname, Const.HTTP_PORT, Const.HTTP_SCHEME);
HttpGet get = new HttpGet();
ResponseHandler<String> responseHandler = new BasicResponseHandler();
AndroidHttpClient client = AndroidHttpClient.newInstance(null);
// execute
response = client.execute(target, get, responseHandler); // this is where the exception is thrown
joResponse = new JSONObject(response);
}
catch (ClientProtocolException e)
{
}
catch (IOException e)
{
}
catch(Exception e)
{
}
Upvotes: 0
Views: 218
Reputation: 25761
Do you have the internet permission declared in your app?
You need to add the following line to your AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
Upvotes: 1