java.lang.IllegalArgumentException: 协议 = http 主机 = null [英] java.lang.IllegalArgumentException: protocol = http host = null

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

问题描述

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

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

    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();

我收到此异常:

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)

我的代码有什么问题?

推荐答案

当 URL 以 http:// 而不是 http:// 开头时,我遇到了同样的异常.例如http://www.example.com

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

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

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

这篇关于java.lang.IllegalArgumentException: 协议 = http 主机 = null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆