java.lang.IllegalArgumentException: host parameter is null

来源:互联网 发布:vs2017怎么编写c语言 编辑:程序博客网 时间:2024/06/05 08:13

使用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;  }


  
阅读全文
0 0
原创粉丝点击