HttpClient exception: java.lang.IllegalArgumentException: host parameter is null

I have the following code

URL targetUrl = ... HttpClient client = new HttpClient(connectionManager); GetMethod getMethod = new GetMethod(); getMethod.setPath(targetUrl.getPath()); HostConfiguration hostConfiguration = getConfiguration(targetUrl) //unknown lib code client.executeMethod(hostConfiguration, getMethod); 

In some cases (on some hosts) I get

java.lang.IllegalArgumentException: host parameter is null"

when calling client.executeMethod.

Why could this happen?

+4
source share
3 answers

This is the script for writing the proxy server http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/ProxyTunnelDemo.java?view=co In my case, the problem was creating the HostConfiguration

0
source

The error message is misleading ...

You should add a protocol in front of the host, something like HTTP:// or whatever you want to use. There may be other circumstances in which this happens, according to this blog post , but setHostConfiguration deprecated, so this only applies to legacy code.

Client code must catch it earlier, and not so deep in the system, how can incorrect data go that far?

+5
source

This error means that you are using an incomplete URL or without a protocol. For example String url ="google.com" . Change it to String url="http://google.com" . He will work now

0
source

All Articles