简体   繁体   English

HttpClient异常:java.lang.IllegalArgumentException:host参数为null

[英]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.

相关问题 改造Java.lang.IllegalArgumentException host == null - Retrofit Java.lang.IllegalArgumentException host == null 我应该如何解决 java.lang.IllegalArgumentException: protocol = https host = null Exception? - How should I resolve java.lang.IllegalArgumentException: protocol = https host = null Exception? java.lang.IllegalArgumentException:protocol = http host = null - java.lang.IllegalArgumentException: protocol = http host = null 原因:java.lang.IllegalArgumentException:主机名不能为null - Caused by: java.lang.IllegalArgumentException: Host name may not be null java.lang.illegalargumentException-由HttpURLConnection getHeaderFieldKey()方法抛出,host = null - java.lang.illegalargumentexception - thrown by HttpURLConnection getHeaderFieldKey() method, host = null 致命异常:java.lang.IllegalArgumentException:需要GoogleApiClient参数 - Fatal Exception : java.lang.IllegalArgumentException: GoogleApiClient parameter is required JAXB给我:java.lang.IllegalArgumentException:参数不能为null - JAXB gives me: java.lang.IllegalArgumentException: is parameter must not be null java.lang.IllegalArgumentException:参数绑定的名称不得为 null 或空 - java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty 线程“ main”中的异常java.lang.IllegalArgumentException:image == null - Exception in thread “main” java.lang.IllegalArgumentException: image == null 给定的 id 不能是 null;。 嵌套异常是 java.lang.IllegalArgumentException - The given id must not be null!; nested exception is java.lang.IllegalArgumentException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM