4

I have next 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"

on client.executeMethod call.

Why may this happen?

3
  • 1
    I was getting this error when I didn't write "http://" in front of my URL. maybe you should try too Commented Apr 30, 2013 at 13:21
  • Currently I debugged code. The cause is that host were not set to HostConfiguration but proxyHost were set. So should I set host when proxyHost is set or this is bug? Commented Apr 30, 2013 at 13:27
  • You don't need HostConfiguration in this case, look at this tutorial: hc.apache.org/httpclient-legacy/tutorial.html Commented Apr 30, 2013 at 13:29

4 Answers 4

8

The error message is misleading...

You must add the 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 article, but setHostConfiguration has been deprecated so this only applies to legacy code.

The client code should catch it earlier instead of failing so deep in the system, how can incorrect data go that far?

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

This is a write exampe of proxy http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/ProxyTunnelDemo.java?view=co In my case problem was in hostConfiguration creation

Comments

0

This typically happens when HttpClient or HttpMethod used does not have a properly set target host or URL.

In my case URL was not properly set so it was NULL.

Double check that the URL is being set properly and not dynamically created from external source. i.e. in my case it was via OpenSearch data.

Or for the testing purposes, you could trying hardcode the URL you wish to have to make sure it is simply because of an URL issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.