本文介绍了HttpClient异常:java.lang.IllegalArgumentException:主机参数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个代码

    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:主机参数为空"

在client.executeMethod调用上.

on client.executeMethod call.

为什么会这样?

推荐答案

这是代理的书面示例 http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/ProxyTunnelDemo.java?view = co 就我而言,问题在于hostConfiguration的创建

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

这篇关于HttpClient异常:java.lang.IllegalArgumentException:主机参数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!