title: ConnectException in Android to access remote server?
body: <p>I am trying to access my remote server using HTTP url connection. I faced the following issue.</p>
  
  <p>When the first time i am trying to connect,it is not connected. After that i restart my device,it's connected. IP address is changed dynamically every day.</p>
  
  <pre><code>java.net.ConnectException: failed to connect to 127.0.0.1(port 80) after 20000ms: isConnected failed: EHOSTUNREACH (No route to host) 
  
  public static boolean isPortalNetworkAvailable(Context context) {
          ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo netInfo = cm.getActiveNetworkInfo();
          HttpRequest.doCheck();
          if (netInfo != null &amp;&amp; netInfo.isConnected()) {
              try {
                  String url1="http://127.0.0.01/";
                  System.out.println("url1"+url1);
                  URL url = new URL(url1);
                  HttpURLConnection urlc = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
                  urlc.setConnectTimeout(20000);
                  urlc.connect();
                  System.out.println("code" + urlc.getResponseCode());
              } catch (MalformedURLException e1) {
                  e1.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }catch (Exception e2) {
                  e2.printStackTrace();
              }
          }
          return false;
  
      }
  </code></pre>
  
  <p>How to resolve this issue ?</p>