更新时间:2023-11-10 08:22:46
我遇到了同样的问题,并且与 HTTPS 有关.如果您致电:
I had the same problem and it was related to HTTPS. If you call:
URL url = new URL("https://www.example.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
您实际上获得了一个不会自动处理gzip的HttpsURLConnection(HttpURLConnection的子类)的实例. 在这种情况下,您可以:
you actually get an instance of HttpsURLConnection (a subclass of HttpURLConnection) that does NOT handle gzip automatically. In those cases you can:
conn.setRequestProperty("Accept-Encoding", "gzip");
...
InputStream inStream = new GZIPInputStream(conn.getInputStream());