[英]HttpClient exception: java.lang.IllegalArgumentException: host parameter is null
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. 在client.executeMethod调用。
Why may this happen? 为什么会这样?
The error message is misleading... 错误消息具有误导性......
You must add the protocol in front of the host, something like HTTP://
or whatever you want to use. 您必须在主机前添加协议 ,例如HTTP://
或您想要使用的任何内容。 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. 根据这篇博客文章 ,可能还有其他情况会发生这种情况,但不推荐使用setHostConfiguration
因此这仅适用于遗留代码。
The client code should catch it earlier instead of failing so deep in the system, how can incorrect data go that far? 客户端代码应该提前捕获它而不是在系统中如此深入地失败,不正确的数据怎么会走得那么远?
这是一个代理的书面例子http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/ProxyTunnelDemo.java?view=co在我的情况下问题是在hostConfiguration创建中
This error means that you are using incomplete url or without protocol. 此错误表示您使用的是不完整的URL或没有协议。 For example String url ="google.com"
. 例如, String url ="google.com"
。 Change it to String url="http://google.com"
. 将其更改为String url="http://google.com"
。 It will work now 它现在可以工作了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.