使用commons-httpclient-3.1.jar的httpclient调用远程系统时,出现java.lang.IllegalArgumentException: host parameter is null 异常,最初以为是因为请求路径没有携带协议(如http://)导致的,后来发现时请求路径的主机地址为null导致。这是在后来查看错误日志时,发现错误来源于HttpConnection,这个异常是在传入的host为空的时候出现的异常,部分源码如下:
public HttpConnection(String proxyHost, int proxyPort, String host, int port, Protocol protocol)
{
if (host == null) {
throw new IllegalArgumentException("host parameter is null");
}
if (protocol == null) {
throw new IllegalArgumentException("protocol is null");
}
this.proxyHostName = proxyHost;
this.proxyPortNumber = proxyPort;
this.hostName = host;
this.portNumber = protocol.resolvePort(port);
this.protocolInUse = protocol;
}