我正在使用AndroidHttpClient从我的代码中获得一个IOException。代码有什么问题吗?无论我使用port 80还是port 443,以及使用Http Schema http还是https,都会抛出代码。
这个异常是在client.execute抛出的,...it是一个UnknownHostException异常..我不知道为什么。我可以从浏览器访问服务。
// 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)
{
}发布于 2011-12-06 22:34:51
您的应用程序中是否声明了互联网权限?
您需要将以下行添加到AndroidManifest.xml中
<uses-permission android:name="android.permission.INTERNET" /> https://stackoverflow.com/questions/8401211
复制相似问题