Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

Here is my code:

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 );
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
784 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...