我想向网站提出一个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.
为什么我得到URI can't be null
?
P.S。:我正在使用JDK10
您的代码正常工作。
我对此进行了测试:
String url = "https://google.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect();
可能是您要访问的URL不是 get 类型。检查一下。