Java HttpUrl连接URI可以';不能为空

Java HttpUrl连接URI可以';不能为空,java,Java,我想向网站发出GET请求,但我的GETURI不能为空。 String url = "https://valid_url.com"; HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection(); connection.setRequestMethod("GET"); connection.connect(); //-> java.lang.IllegalArgumentExcepti

我想向网站发出GET请求,但我的GET
URI不能为空。

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不能为null


注意:我正在使用jdk10,您的代码运行良好

我用以下方法测试了代码:

String url = "https://google.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect();

可能是您正在访问的url不是GET类型。检查一下。

也许会有帮助。@MensurQulami我读过,但那个答案对我没有帮助。试试URLConnection