安卓:未知主机异常 [英] Android: UnknownHostException

查看:52
本文介绍了安卓:未知主机异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Android SDK 2.2, testing my application with the emulator. I want to send a HTTP Post. When I do I get a UnknownHostException. I have placed the required permissions
<uses-permission android:name="android.permission.INTERNET" />
in the manifest.xml. Also I can open the browser on the emulator and navigate to the URL with no problem.

这是我的代码:

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 权限标签是清单标签的子标签,而不是应用标签.

The INTERNET permission tag is a child of the manifest tag, not the application tag.

这篇关于安卓:未知主机异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆