如何获得大反响的身体Jsoup

问题描述

告诉我问题出在哪里,以及如何解决。我需要获取一个响应数组json格式。在服务器上,响应在大约30分钟内形成,收集了15万个元素的数组。然后开始派遣,并暂停超过24小时。但是即使经过了这么长的时间,答案仍然没有到来。服务器上没有错误。如果您使用10K,答案将毫无问题。我试图将答案保存到TXT文件中,该文件的大小为+ -35MB,其中包含35K的库存。

这是我执行请求的方式:

Connection.Response response = Jsoup.connect(URLs.sayt + "/" + URLs.api + "/hs/CLIENTS/LIST/")
                    .method(Connection.Method.GET)
                    .maxBodySize(0)
                    .timeout(0)
                    .userAgent(URLs.getUserAgentMobile())
                    .header("Authorization","Basic " + base64login)
                    .header("Accept-Language","*")
                    .header("mode","tobase")
                    .execute();
            if(response != null){
                ArrayList<Client> clients = new Gson().fromJson(response.body(),new Typetoken<List<Client>>() {}.getType());
                for (Client client:clients){
                    sqliteWork.AddToClient(client);
                }
            }

这是json数组中元素的示例:

{"id": "9812d904-2d8a-11e8-80bb-a45d36c35311","name": "Afaq","code": "","isGroup": false,"parent": "null","address": "","phone": "+994(12) 436 71 88","phoneMore": "+994(50)2409696","phoneHome": "","debt": 0 }

解决方法

我没有找到解决问题的方法。我已经尝试了okhttp和httpurlconnection。显然,Android客户端本身在体内不支持这么大的字符串响应。也许这将是通过文件的解决方案。但是,当您需要实际数据时,这不是解决方案。因此,我从服务器响应了1万个元素。满载15万个元素需要2个小时。

请注意,我使用的是最新数据,如果2个小时很长,那么我的应用程序也支持在线模式。

Connection connection = Jsoup.connect(URLs.sayt + "/" + URLs.api + "/hs/CLIENTS/LIST/")
                    .method(Connection.Method.GET)
                    .ignoreContentType(true)
                    .maxBodySize(0)
                    .timeout(0)
                    .userAgent(URLs.getUserAgentMobile())
                    .header("Authorization","Basic " + base64login)
                    .header("Accept-Language","*")
                    .header("mode","tobase");

            Connection.Response response = connection.execute();
            ArrayList<Client> clients = new Gson().fromJson(response.body(),new TypeToken<List<Client>>() {}.getType());
            Client last = null;
            for (Client client:clients){
                last = client;
                sqLiteWork.AddToClient(client);
            }

            while (clients.size() > 0){
                response = connection.header("last",last.id).execute();
                clients = new Gson().fromJson(response.body(),new TypeToken<List<Client>>() {}.getType());
                for (Client client:clients){
                    last = client;
                    sqLiteWork.AddToClient(client);
                }
            }