java.lang.IllegalArgumentException: protocol = http host = null

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25642104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:50:50  来源:igfitidea点击:

java.lang.IllegalArgumentException: protocol = http host = null

javaurlapache-tika

提问by Goko Gorgiovski

For this link http://bits.blogs.nytimes.com/2014/09/02/uber-banned-across-germany-by-frankfurt-court/?partner=rss&emc=rssthis code doesn`t work but if I put another for exemple: https://www.google.comeverything is ok:

对于此链接http://bits.blogs.nytimes.com/2014/09/02/uber-banned-across-germany-by-frankfurt-court/?partner=rss&emc=rss此代码不起作用但如果我再举一个例子:https: //www.google.com一切正常:

    URL url = new URL("http://bits.blogs.nytimes.com/2014/09/02/uber-banned-across-germany-by-frankfurt-court/?partner=rss&emc=rss");
        URLConnection uc;
    uc = url.openConnection();
    uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16");
    uc.addRequestProperty("referer", "http://www.facebook.com");
    uc.connect();     

    this.input = uc.getInputStream();

I get this exception:

我得到这个例外:

java.lang.IllegalArgumentException: protocol = http host = null
    at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:170)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:926)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2398)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1557)
    at UrlParser.<init>(UrlParser.java:48)
    at TikaParser.test_url_parser(TikaParser.java:186)
    at TikaParser.run(TikaParser.java:256)
    at java.lang.Thread.run(Thread.java:745)

what is wrong with my code?

我的代码有什么问题?

回答by Kai Sternad

Looks like your proxy host is not set. Try setting it, then it should work.

看起来您的代理主机未设置。尝试设置它,然后它应该可以工作。

See this pagefor more information on proxy properties.

有关代理属性的更多信息,请参阅此页面

回答by wsams

I encountered this same exception when the URL started with http:/instead of http://. e.g. http:/www.example.com

当 URL 以http:/而不是http://. 例如http:/www.example.com

This was in the org.springframework.web.client.RestTemplate.exchange()method, so it's not quite the same context, but maybe a similar issue.

这是在org.springframework.web.client.RestTemplate.exchange()方法中,所以它不是完全相同的上下文,但可能是一个类似的问题。

回答by Dhirendra Gautam

Mostly this error occur due to incorrect url. Make sure the Url that you are hitting is correct.As wsams mentioned try to check the // in your url if it is correct or not. Correct pattern is http://localhost:8080

大多数情况下,此错误是由于 url 不正确造成的。确保您点击的 Url 是正确的。正如 wsams 提到的,尝试检查您的 url 中的 // 是否正确。正确的模式是http://localhost:8080