gpt4 book ai didi

java - AndroidHttpClient 的问题

转载 作者:行者123 更新时间:2023-12-01 15:38:54 25 4
gpt4 key购买 nike

我使用 AndroidHttpClient 从我的代码中收到 IOException。代码有问题吗?无论我使用端口 80 还是 端口 443,以及使用 Http 架构 httphttps,都会引发代码。

异常在client.execute处抛出...这是一个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)
{
}

最佳答案

您的应用程序中是否声明了互联网权限?

您需要将以下行添加到 AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" /> 

关于java - AndroidHttpClient 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com