Estoy usando Android SDK 2.2, probando mi aplicación con el emulador. Quiero enviar una publicación HTTP. Cuando lo hago obtengo una UnknownHostException. He colocado los permisos necesarios
<uses-permission android:name="android.permission.INTERNET" /
>
en manifest.xml. También puedo abrir el navegador en el emulador y navegar a la URL sin ningún problema.Android: UnknownHostException
Aquí está mi código:
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);
}
'} \t \t \t catch (Exception e) \t \t \t { \t \t \t \t System.out.println ("Error:" + e); \t \t \t} \t \t captura (ClientProtocolException e) \t \t { \t \t Log.e ("HttpManager", "ClientProtocolException arrojados" + e); \t \t} \t \t catch (IOException e) { \t \t \t \t Log.e ("HttpManager", "IOException arrojados" + e); \t \t} ' Esto muestra el error indica que ya se trató excepción. –