1

LGE G2 デバイスの UrlConnection クラスに問題があります。どういうわけか同じコードが他のデバイスで動作しています。また、URLを別のものに変更すると、DLが動いているようです。そのため、問題はサーバー側にある可能性があります。

4.4.2 android を搭載した Galaxy SIV で同じ URL へのコードもテストしましたが、すべて正常に動作しているようです。

また、任意の Web ブラウザを使用して同じ URL からファイルをダウンロードできます...

これはスタック トレースです。

04-17 12:17:35.681: W/System.err(10695): java.net.ProtocolException: Unexpected status line: HTTP/1.1 
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.RawHeaders.setStatusLine(RawHeaders.java:108)
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:308)
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:135)
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:644)
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
04-17 12:17:35.681: W/System.err(10695):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.getHeaderField(HttpURLConnectionImpl.java:143)
04-17 12:17:35.681: W/System.err(10695):    at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:544)
04-17 12:17:35.681: W/System.err(10695):    at java.net.URLConnection.getContentLength(URLConnection.java:316)

コード:

URL url = new URL(resource);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(TEST_TIMEOUT);
connection.setReadTimeout(TEST_TIMEOUT);

int fileSize = connection.getContentLength();

InputStream inputStream = connection.getInputStream();
BufferedInputStream bufferedInputStream = new BufferedInputStream(
                inputStream);

UrlConnection の標準的な使い方です。HttpUrlConnection または HttpsUrlConnection を使用する場合も同様です。そして、私が言ったように、このエラーは LGE G2 でのみ発生します。Nexus 4、Xperia Z1、Galaxy SIV でテストしたところ、すべて正常に動作しました。BR、JDK

4

0 に答える 0