Java HttpClient cannot parse IP address in Android

Edited: bug fix in uri

I am using an instance of org.apache.http.client.HttpClient to connect to a REST-based web service on a local network:

String uri = "http://192.168.0.101:8888/someinstance/someresource?name=blah&age=blah"; final HttpGet request = new HttpGet(uri); final HttpClient httpClient = new DefaultHttpClient(); final HttpResponse response = httpClient.execute(request); 

This works fine on HTC Incredible with 2.3.3, but on HTC Wildfire with 2.2.1 it raises an IllegalArgumentException with the message: The target node must not be null.

If I use uri using the hostname instead of the IP address, the problem does not occur. For example, the following is executed without errors:

 String uri = "http://www.somehost.com:8888/someinstance/someresource?name=blah&age=blah"; 

Can anyone tell me what I'm doing wrong. Assuming I should use an IP address, is there a way around this?

Thanks for any advice.

+4
source share

Source: https://habr.com/ru/post/1380557/


All Articles