简体   繁体   English

HttpURLConnection URI不能为null

[英]HttpURLConnection URI can't be null

I want to make a GET request to an website, but I get URI can't be null. 我想向网站发出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 ? 为什么我得到的URI can't be null

PS: I'm using jdk10 PS:我正在使用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. 可能是您正在访问的网址不是GET类型。 Check for that. 检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM