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
?
PS: I'm using jdk10
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.