以下のコードを使用して URL を接続します。
URL url = new URL(URLPath);
HttpsURLConnection HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setAllowUserInteraction(true);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Accept", "*/*");
InputStream respondsStream = connection.getInputStream();
しかし、次のようにオンラインでエラーが発生しInputStream respondsStream = connection.getInputStream();
ます。
04-11 14:16:11.445: W/System.err(26576): java.io.FileNotFoundException: URLPath
04-11 14:16:11.445: W/System.err(26576): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
04-11 14:16:11.445: W/System.err(26576): at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:246)
しかし、ブラウザーで URLPath を入力しようとすると、応答が成功する可能性があります。
ネットワークが機能していることを確認しました。
エラーを回避するためにコードを変更するにはどうすればよいですか?