gpt4 book ai didi

安卓:未知主机异常

转载 作者:IT老高 更新时间:2023-10-28 13:14:56 36 4
gpt4 key购买 nike

我正在使用 Android SDK 2.2,使用模拟器测试我的应用程序。我想发送一个 HTTP Post。当我这样做时,我得到一个 UnknownHostException。我已经放置了所需的权限
<uses-permission android:name="android.permission.INTERNET" / >
在 manifest.xml 中。我也可以在模拟器上打开浏览器并毫无问题地导航到 URL。

这是我的代码:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost( uri );
HttpResponse response = null;
try
{
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2 );
nameValuePairs.add( new BasicNameValuePair( "id", "edit-name" ) );
nameValuePairs
.add( new BasicNameValuePair( "stringdata", userName ) );
httppost.setEntity( new UrlEncodedFormEntity( nameValuePairs ) );

// Execute HTTP Post Request
response = httpclient.execute( httppost );
// Log.i( "HttpManager:", "======> response: "
// + response.getEntity().getContent() );

}
catch (ClientProtocolException e)
{
Log.e( "HttpManager", "ClientProtocolException thrown" + e );
}
catch (IOException e)
{
Log.e( "HttpManager", "IOException thrown" + e );
}

最佳答案

INTERNET 权限标签是 list 标签的子标签,而不是应用标签。

关于安卓:未知主机异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3314137/

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