No se puede resolver host: URL Ninguna dirección asociada con hostname

Tengo una llamada de servicio web para derribar un objeto JSON y sólo funciona si tengo la dirección IP y no el nombre de host. He estado bien usando direcciones IP, pero ahora necesito tener el nombre de host.

Aquí está mi código

StringBuilder stringBuilder = new StringBuilder(); HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 3000); HttpConnectionParams.setSoTimeout(httpParams, 7000); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); HttpPost httpost = new HttpPost(URL); try { HashMap<String,String> params = new HashMap<String,String>(); // Login info params.put("username", edtUserName.getText().toString()); params.put("password", edtPass.getText().toString()); params.put("deviceOS", "Android"); params.put("deviceOSVersion", android.os.Build.VERSION.RELEASE); params.put("language", "0"); //JSON object holding the login info JSONObject holder = new JSONObject(params); StringEntity se = new StringEntity(holder.toString()); httpost.setEntity(se); httpost.setHeader("Content-Type", "application/json"); //Executing the call HttpResponse response = httpClient.execute(httpost); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream inputStream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { stringBuilder.append(line); } inputStream.close(); } else { returnCode = -1; Log.d("JSON", "Failed to download file"); } } catch (Exception e) { returnCode = -1; Log.d("readJSONFeed", e.getLocalizedMessage()); } return stringBuilder.toString(); 

No sé por qué eso no funciona. Estoy probando en un teléfono con conexión Wifi, Mi manifiesto tiene el <uses-permission android:name="android.permission.INTERNET" /> y <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Este servicio web funciona. Simplemente no en Android

Si alguien tiene una idea que sería genial, gracias.

Lo arreglé eliminando estas líneas

 HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 3000); HttpConnectionParams.setSoTimeout(httpParams, 7000); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); 

Y reemplazándolo con este código

 HttpClient httpClient = MainActivity.createHttpClient(); public static HttpClient createHttpClient(){ try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new MySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 15000); HttpConnectionParams.setSoTimeout(params, 5000); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } } 
  • POST con Android Retrofit
  • AndroidHttpClient Nullpointerexception llamando a android.net.http.AndroidHttpClient.isMmsRequest
  • Métodos de HTTP desautorizado advertencia en el estudio de Android
  • POST Multipart Form Datos usando Retrofit 2.0 incluyendo imagen
  • AndroidHttpClient versus HttpUrlConnection para API Nivel 9 y superior
  • ¿Cómo reempaquetar HttpClient 4.3.1 y eliminar las dependencias en commons-logging?
  • Compilación de la biblioteca de descargas de Google API 23 Android Marshmallow
  • Publicar campos en este formato con Retrofit
  • No se puede resolver el símbolo HttpEntity, HttpResponse
  • AsyncHttpclient de Loopj no establece el tiempo de espera correcto
  • Google Volley vs Android-Async-Http
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.