Reputation: 3225
I want to make a GET request to an website, but I get URI can't be null.
String url = "https://valid_url.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect(); //-> java.lang.IllegalArgumentException: URI can't be null.
Why I get URI can't be null
?
P.S.: I'm using jdk10
Upvotes: 2
Views: 1063
Reputation: 16439
Your code is working fine.
I tested the code with this :
String url = "https://google.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect();
May be the url you are accessing is not GET type. Check for that.
Upvotes: 2