[英]HttpURLConnection 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.
為什么我得到的URI can't be null
?
PS:我正在使用jdk10
您的代碼運行正常。
我用這個測試了代碼:
String url = "https://google.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect();
可能是您正在訪問的網址不是GET類型。 檢查一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.