readutf异常_Android HTTPS con.getResponseCode()在大请求中对readUtf8LineStrict引发EndOfFile异常...

THE PROBLEM

I have a post request is causing an error only when data to recover are long (about 60Mb of data in json format).

The same request with less information does not cause any errors and it works perfectly.

The error message that is always appearing at exactly 2 minutes haver made the request, is the folowing:

java.io.EOFException

at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:98)

at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:202)

at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:119)

at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:798)

at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:405)

at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:349)

at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:517)

at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)

at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)

at com.myproject.mypackage.DataManagerService$ServiceHandler.sincronitzar_baixada_dades(DataManagerService.java:1406)

at com.myproject.mypackage.DataManagerService$ServiceHandler.handleMessage(DataManagerService.java:403)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:135)

at android.os.HandlerThread.run(HandlerThread.java:61)

On the server side, we found that the service is preparing the data still alive after the error occurs on my device.

A few days ago we increased the RAM on the server to avoid OOM errors in the same casuistry.

MORE CODE UPDATED 03/06/2016

also attached the code that makes the request and saves the response in a file on the device:

The request code:

HttpsURLConnection con = (HttpsURLConnection) Https_url.openConnection();

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1){

con.setRequestProperty("Connection", "close");

}

con.setReadTimeout(DEFAULT_RESPONSE_TIMEOUT);

con.setConnectTimeout(DEFAULT_RESPONSE_TIMEOUT);

con.setRequestMethod("POST");

con.setRequestProperty("Accept-Encoding","identity");

con.setDoInput(true);

con.setDoOutput(true);

con.connect();

int status = con.getResponseCode();

if (status >= 400) {

inputStreamPujada = con.getErrorStream();

}

else{

inputStreamPujada = con.getInputStream();

}

if (inputStreamPujada != null){

try {

OutputStream out = new FileOutputStream(file);

byte[] buf = new byte[1024];

int len;

while((len=in.read(buf))>0){

out.write(buf,0,len);

}

out.close();

in.close();

}

catch (Exception e) { e.printStackTrace(); }

}

WHAT WE TRYED?

We tryed to format json outputs with no breaklines and also with pretty json format.

It seems that error is caused because the DataStream dosen't found an "\n" and throws an EndOfFile Exception

Also tryed to raise up the memory RAM in the server side with no more effect.

Also tryed edit the request property "Accept-Encoding" as this question

THE QUESTION

What is the cause of this EOFException? Why is working with low data and throwing this in big data? Ther are some extrange timeout or library limit with max time in 2 minutes?

Thanks in advance!

解决方案

After much research, we modify the server side to send the volume of data in a paged system of 5000 records for every flush of the JSON file.

It seems that the server was blocked by addressing data and that made the request ends with a EOFException as shown in the question.

I hope this question will be useful to someone else someday.

Thank you!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值