java.lang.IllegalArgumentException: host parameter is null

本文探讨了使用commons-httpclient-3.1.jar时遇到的java.lang.IllegalArgumentException:hostparameterisnull异常问题。此异常源于请求路径中主机地址为空。文章通过分析HttpConnection构造函数源码揭示了异常产生的原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值