Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unable to resolve host "xxx.xxx.61.116:8087": No address associated with hostname #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jpujolji opened this issue Oct 17, 2015 · 16 comments
Assignees
Labels
Milestone

Comments

@jpujolji
Copy link

I'm trying to consume a SOAP service with the version 1.4.9 but I have an error and with the version 1.4.7 works fine.

W/System.err: java.net.UnknownHostException: Unable to resolve host "static-xxx-xxx-61-116.une.net.co": No address associated with hostname
W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:427)
W/System.err:     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W/System.err:     at java.net.InetAddress.getByName(InetAddress.java:305)
W/System.err:     at cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:154)
W/System.err:     at cz.msebera.android.httpclient.conn.scheme.SchemeSocketFactoryAdaptor.connectSocket(SchemeSocketFactoryAdaptor.java:65)
W/System.err:     at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
W/System.err:     at cz.msebera.android.httpclient.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:145)
W/System.err:     at cz.msebera.android.httpclient.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131)
W/System.err:     at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
W/System.err:     at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
W/System.err:     at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:860)
W/System.err:     at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:146)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:177)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:106)
W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:818)

The error happens when the url has a port associated, with not using the port works well.
example:
This works:

http://xxx.xxx.195.171/wsgenesis/wsgenesis.asmx

This does not work:

http://xxx.xxx.61.116:8087/wsgenesis/wsgenesis.asmx

This is my code:

    client = new AsyncHttpClient();
    client.setTimeout(20000);
    String soapAction = "http://navacom.com.co/Login";

    client.addHeader("Content-Type", "text/xml; charset=utf-8");
    client.addHeader("SOAPAction", soapAction);
    String contentType = "text/xml; charset=utf-8";

    StringEntity entity = null;
    try {
        entity = new StringEntity(body, "utf-8");
        entity.setContentType("text/xml; charset=utf-8");
        entity.setChunked(true);
    } catch (IllegalArgumentException e) {
        Log.d("Depuracion", "StringEntity: IllegalArgumentException " + e);
    }
    String serverUrl = url + "?op=Login";

    client.post(mContext, serverUrl, entity, contentType, new AsyncHttpResponseHandler() {
        ....
        ....
    });
@alexdg09
Copy link

I'm having the same error but with a different IP address, I'm testing in android 4.3, 4.4 and 5.1 and I'm having the same error with the version 1.4.9. I change the version of the library in my app to 1.4.8 and using the org.apache.http.legacy.jar library and everything works fine.

@alexdg09
Copy link

I'm compiling the app with gradle and android sdk version 23.

@m0sk1t
Copy link

m0sk1t commented Nov 11, 2015

Simular error with 46.101.219.185 (DigitalOcean Droplet), this IP resolves to Droplet name...

@susuzero
Copy link

I have the same problem when i use the version 1.4.9, but 1.4.7 works fine

@smarek smarek added this to the 1.4.9.1 milestone Nov 17, 2015
@smarek smarek self-assigned this Nov 17, 2015
@yiqiejieyoukeneng
Copy link

@Archieeeeee
Copy link

Same error but I'm using 80 port, I have many servers using IP addresses directly to access URL resource, I need advice to quick fix this problem under 1.4.9 version, could you help me, thank you

@sean-lin
Copy link

https://github.com/loopj/android-async-http/blob/master/library/src/main/java/com/loopj/android/http/AsyncHttpClient.java#L312-L313

Scheme() was changed since 4.1
the old API was using SchemeSocketFactoryAdaptor and this class is deprecated.

When connecting a server with a IP in the URL and the IP is under another domain that has many IPs, the client may try to connect another IP resolved from that domain.

try this case

http://119.29.29.29/d?dn=github.com

@indiefr
Copy link

indiefr commented Mar 16, 2016

@alexdg09 but, how add this librarys, i try to add to my projct but not solved the error.

@indiefr
Copy link

indiefr commented Mar 16, 2016

@alexdg09 when i add the library 1.4.7 i has a error in HEader class, this class no exists in this version.

@alexdg09
Copy link

@indiefr you need to work for now with the version 1.4.8 from the android-async-http library. To use this library you can add to your gradle file this line:

compile 'com.loopj.android:android-async-http:1.4.8'

Also you need to download the jar file org.apache.http.legacy.jar and also add this file to your gradle file, just copy that file to your libs folder and then add this line in your gradle file:

compile files('libs/org.apache.http.legacy.jar')

The Header class is from that jar file not from android-async-http library.

I hope this help you.

@chingiz
Copy link

chingiz commented Apr 11, 2016

@alexdg09 I did what you prefered, but I still have the same problem.

@joeljoaquin1994
Copy link

Your network cannot resolve the hostname api.forecast.io. Are you connected to the internet?
This error is due to api.forecast.io not being able to be translated to an IP address via DNS.

@sumknot
Copy link

sumknot commented Feb 10, 2017

got the same problem on 1.4.9, but finally switched to 1.4.8 is ok.

@daivy
Copy link

daivy commented Mar 20, 2017

android {
    compileSdkVersion 24
    buildToolsVersion '25.0.2'
    ...
    useLibrary 'org.apache.http.legacy'
}

Lib for classes such as Header[] and BasicClientCookie (deprecated)

dependencies {
    ...
    compile 'com.loopj.android:android-async-http:1.4.8'
}

Working version

Fixed my issue : No address associated with hostname

@kienvn
Copy link

kienvn commented Jun 20, 2017

Hi all,
I found this issue not related with loopj
I fixed it by modify in lib HttpClient:

cz\msebera\android\httpclient\conn\scheme\SchemeSocketFactoryAdaptor.java

@OverRide
public Socket connectSocket(
final Socket sock,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
String host = remoteAddress.getHostName();
int port = remoteAddress.getPort();
InetAddress local = null;
int localPort = 0;
if (localAddress != null) {
local = localAddress.getAddress();
localPort = localAddress.getPort();
}
try{
return this.factory.connectSocket(sock, host, port, local, localPort, params);
}catch(Exception e)
{
if (remoteAddress instanceof HttpInetSocketAddress) {
host = ((HttpInetSocketAddress)remoteAddress).getHttpHost().getHostName();
port = ((HttpInetSocketAddress)remoteAddress).getHttpHost().getPort();
return this.factory.connectSocket(sock, host, port, local, localPort, params);
}else
{
return this.factory.connectSocket(sock, host, port, local, localPort, params);
}
}
}

smarek pushed a commit that referenced this issue Jul 13, 2019
* issue #998: update httpclient to fix unable resolve host issue

* fix issue #998

update http client to fix unable resolve host issue

* update project gradle version

* change ConcurrentSkipList to ConcurrentSkipListMap
- ConcurrentSkipList is unavailable in java anymore

* remove buildToolsVersion and compileOptions to clear gradle warning

* remove buildToolsVersion and compileOptions to clear gradle warning

* fix productFlavors config to clear gradle error

* change withLeakCanaryCompile to withLeakCanaryImplementation to clear gradle warning
@smarek
Copy link
Member

smarek commented Jul 13, 2019

This issue should be fixed with PR #1317 merged just now, release containing this fix will be ready on monday

@smarek smarek closed this as completed Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests