問(wèn)題描述
我正在使用 Android SDK 2.2,使用模擬器測(cè)試我的應(yīng)用程序.我想發(fā)送一個(gè) HTTP Post.當(dāng)我這樣做時(shí),我得到一個(gè) UnknownHostException.我已放置所需的權(quán)限
在 manifest.xml 中.我也可以在模擬器上打開(kāi)瀏覽器并毫無(wú)問(wèn)題地導(dǎo)航到 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 權(quán)限標(biāo)簽是清單標(biāo)簽的子標(biāo)簽,而不是應(yīng)用標(biāo)簽.
The INTERNET permission tag is a child of the manifest tag, not the application tag.
這篇關(guān)于安卓:未知主機(jī)異常的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!