崑:
私は、ウェブサイトへの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を使用しています
アニッシュB.:
あなたのコードは正常に動作しています。
私はこれを使用してコードをテストしました:
String url = "https://google.com";
HttpURLConnection connection = (HttpURLConnection)(new URL(url)).openConnection();
connection.setRequestMethod("GET");
connection.connect();
あなたがアクセスしているURLはないかもしれGETのタイプ。そのために確認してください。