相关疑难解决方法(0)

java.io.IOException出现此错误的原因是什么:Content-Length和流长度不一致

我收到了这个错误

   java.io.IOException: Content-Length and stream length disagree
Run Code Online (Sandbox Code Playgroud)

在这行代码上 return response.body().bytes();

这是完整的代码

编辑:在一些谷歌之后,错误的原因来自okhttp lib

if (contentLength != -1L && contentLength != bytes.size.toLong()) {
  throw IOException(
      "Content-Length ($contentLength) and stream length (${bytes.size}) disagree")
}
Run Code Online (Sandbox Code Playgroud)

但是如何解决这个问题?

编辑:

在此输入图像描述

这是完整的代码:

public class OkHttpHandler extends AsyncTask<Void, Void, byte[]> {

    private final String Fetch_URL = "http://justedhak.comlu.com/get-data.php";
    ArrayList<Listitem> Listitem;
    int resulta;

    OkHttpClient httpClient = new OkHttpClient();

    String myJSON;
    JSONArray peoples = null;
    InputStream inputStream = null;

    @Override
    protected byte[] doInBackground(Void... params) {
        Log.d("e", "dddddddddd");
        Log.d("e", Fetch_URL);

        Request.Builder …
Run Code Online (Sandbox Code Playgroud)

android okhttp

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

okhttp ×1