I want to download a zip file from the server and save it on sdcard so i search on SF and find this solution and this link
i can successfully get the length of data and it's print the header.
@Override
public void onResponse(Response response) throws IOException {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
System.out.println(response.body().string());
}
so at this steps how to save zip file on disk and the other problem is after a seconds i get this log
01-09 18:12:19.528 17196-17941/com.myapp I/System.out: Content-Type: application/zip
01-09 18:12:19.528 17196-17941/com.myapp I/System.out: Content-Length: 13467179
01-09 18:12:19.528 17196-17941/com.myapp I/System.out: Vary: User-Agent
01-09 18:12:19.528 17196-17941/com.myapp I/System.out: OkHttp-Sent-Millis: 1452363138725
01-09 18:12:19.528 17196-17941/com.myapp I/System.out: OkHttp-Received-Millis: 1452363139533
01-09 18:12:26.608 17196-17515/com.myapp I/okhttp3.OkHttpClient: Callback failure for call to http://myapp.com....
java.net.SocketTimeoutException
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
at okio.RealBufferedSource.read(RealBufferedSource.java:50)
at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:382)
at okio.Buffer.writeAll(Buffer.java:956)
at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:92)
at okhttp3.ResponseBody.bytes(ResponseBody.java:83)
at okhttp3.ResponseBody.string(ResponseBody.java:109)
at com.myapp.GetDataActivity$1.onResponse(GetDataActivity.java:99)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
01-09 18:12:49.380 17196-17941/com.myapp I/okhttp3.OkHttpClient: Callback failure for call to http://www.myapp.com/...
java.net.SocketTimeoutException
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
at okio.Okio$2.read(Okio.java:139)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
at okio.RealBufferedSource.read(RealBufferedSource.java:50)
at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:382)
at okio.Buffer.writeAll(Buffer.java:956)
at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:92)
at okhttp3.ResponseBody.bytes(ResponseBody.java:83)
at okhttp3.ResponseBody.string(ResponseBody.java:109)
at com.myapp.GetDataActivity$1.onResponse(GetDataActivity.java:99)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)