java.net.SocketTimeoutException:下载 google 电子表格时读取超时
java.net.SocketTimeoutException: Read timed out while downloading google spreadsheet
我有一段代码可以下载 google 电子表格
File file = service.files().get(spreadsheetID).execute();
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl))
.setConnectTimeout(0).execute();
连接超时默认为 20 秒。我试图将它设置为不同的值,但它不起作用。我不断收到
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_60]
at java.net.SocketInputStream.read(SocketInputStream.java:152) ~[na:1.7.0_60]
at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_60]
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) ~[na:1.7.0_60]
at sun.security.ssl.InputRecord.read(InputRecord.java:480) ~[na:1.7.0_60]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) ~[na:1.7.0_60]
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884) ~[na:1.7.0_60]
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) ~[na:1.7.0_60]
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) ~[na:1.7.0_60]
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) ~[na:1.7.0_60]
at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ~[na:1.7.0_60]
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687) ~[na:1.7.0_60]
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633) ~[na:1.7.0_60]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323) ~[na:1.7.0_60]
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) ~[na:1.7.0_60]
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338) ~[na:1.7.0_60]
at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:36) ~[google-http-client-1.19.0.jar:1.19.0]
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94) ~[google-http-client-1.19.0.jar:1.19.0]
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965) ~[google-http-client-1.19.0.jar:1.19.0]
你还需要设置ReadTimeout
可能是文档太大
我有一段代码可以下载 google 电子表格
File file = service.files().get(spreadsheetID).execute();
String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl))
.setConnectTimeout(0).execute();
连接超时默认为 20 秒。我试图将它设置为不同的值,但它不起作用。我不断收到
Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_60] at java.net.SocketInputStream.read(SocketInputStream.java:152) ~[na:1.7.0_60] at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_60] at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) ~[na:1.7.0_60] at sun.security.ssl.InputRecord.read(InputRecord.java:480) ~[na:1.7.0_60] at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) ~[na:1.7.0_60] at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884) ~[na:1.7.0_60] at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) ~[na:1.7.0_60] at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) ~[na:1.7.0_60] at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) ~[na:1.7.0_60] at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ~[na:1.7.0_60] at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687) ~[na:1.7.0_60] at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633) ~[na:1.7.0_60] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323) ~[na:1.7.0_60] at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468) ~[na:1.7.0_60] at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338) ~[na:1.7.0_60] at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:36) ~[google-http-client-1.19.0.jar:1.19.0] at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94) ~[google-http-client-1.19.0.jar:1.19.0] at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965) ~[google-http-client-1.19.0.jar:1.19.0]
你还需要设置ReadTimeout 可能是文档太大