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一切正常:java.lang.IllegalArgumentException异常:协议= HTTP主机= NULL
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
这是在org.springframework.web.client.RestTemplate.exchange()
方法,所以它不是完全相同的上下文,但也许是一个类似的问题。
你能举个例子吗? – 2014-09-03 11:10:51
尝试通过命令行设置-Dhttp.proxyHost = yourproxyhost – 2014-09-03 11:22:39