java.lang.IllegalArgumentException: protocol = http host = null
Asked Answered
V

4

15

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

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?

Vasta answered 3/9, 2014 at 10:35 Comment(0)
H
47

I encountered this same exception when the URL started with http:/ instead of http://. e.g. 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.

Hienhieracosphinx answered 14/2, 2015 at 20:25 Comment(2)
http:// became http:/ when I accidentally passed the URL in a pathlib.Path() in Python.Corcyra
Yes... That's it. I should've looked more closely sooner, but didn't. Like you know when you're sure that something can't be the error. Definitely not. Until you think, once again, "Welcome to the IT" ;-)Letter
H
2

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

Highspirited answered 23/10, 2018 at 12:15 Comment(0)
Q
0

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

See this page for more information on proxy properties.

Quickstep answered 3/9, 2014 at 10:45 Comment(2)
can you give me example?Vasta
try setting -Dhttp.proxyHost=yourproxyhost through the command lineQuickstep
I
0

Easy solution: In gradle-wrapper.properties just hav a look at distribution url. Make it correct like this;

distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

Its working properly

Indrawn answered 15/10, 2022 at 16:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.