Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that it's working correctly. Ports designated that way are correct for protocols like http and in URLs but not for host addresses. I think you'll need to strip off the port part to call getByName.</p> <p>If you have a full url like <a href="http://host.com:85/foo/bar.html" rel="nofollow">http://host.com:85/foo/bar.html</a> you can use something like the following to get a host address:</p> <pre><code>public static String extractAddressFromUrl(String url) { String urlToProcess = null; //find protocol int protocolEndIndex = url.indexOf("://"); if(protocolEndIndex&gt;0) { urlToProcess = url.substring(protocolEndIndex + 3); } else { urlToProcess = url; } // If we have port number in the address we strip everything // after the port number int pos = urlToProcess.indexOf(':'); if (pos &gt;= 0) { urlToProcess = urlToProcess.substring(0, pos); } // If we have resource location in the address then we strip // everything after the '/' pos = urlToProcess.indexOf('/'); if (pos &gt;= 0) { urlToProcess = urlToProcess.substring(0, pos); } // If we have ? in the address then we strip // everything after the '?' pos = urlToProcess.indexOf('?'); if (pos &gt;= 0) { urlToProcess = urlToProcess.substring(0, pos); } return urlToProcess; } </code></pre> <p>Also, if youre trying to find out if a host is available you might consider using <a href="http://developer.android.com/reference/android/net/ConnectivityManager.html#requestRouteToHost%28int,%20int%29" rel="nofollow">ConnectivityManager.requestRouteToHost()</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload