There is a common code.

The problem is that the result I get is not complete. And only some part, that is, sales are not part, but the first 4066 characters. Changed the full code. The problem is the same, IOException does not seem to be called

private class GetContent extends AsyncTask<Void, Void, String>{ HttpURLConnection urlConnection = null; BufferedReader reader = null; String resultJson = ""; @Override protected String doInBackground(Void... params) { try{ URL url = new URL("http://www.json-generator.com/api/json/get/bSFiRdwiSq?indent=2"); urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null){ buffer.append(line); } resultJson = buffer.toString(); Log.d("Result:", resultJson); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } } 

Here is the result

 D/RESULT:: [ { "guid": "fdaefcc1-6469-4e3a-9d03-722f8de768d9", "index": 0, "favoriteFruit": "banana", "latitude": 52.644930000000002, "company": "DECRATEX", "email": "jodiecollier@decratex.com", "picture": "http://placehold.it/32x32", "tags": [ "esse", "tempor", "fugiat", "labore", "eu", "aliquip", "fugiat" ], "registered": "2015-06-07T09:21:48 -06:00", "eyeColor": "blue", "phone": "+1 (870) 541-3015", "address": "503 Rugby Road, Defiance, Alaska, 2923", "friends": [ { "id": 0, "name": "Melton Reese" }, { "id": 1, "name": "Sara Gilbert" }, { "id": 2, "name": "Nicholson Weber" } ], "isActive": false, "about": "Fugiat Lorem mollit in pariatur incididunt est cupidatat veniam sit officia. Dolor dolor velit ex fugiat dolore officia enim quis in pariatur do ea. Ipsum cillum duis aliquip ut occaecat qui sint est aliqua consequat reprehenderit non. Velit pariatur aute voluptate minim in deserunt amet duis laborum laborum amet. Fugiat nostrud culpa ipsum Lorem proident pariatur aliqua fugiat culpa. Et aliquip magna exercitation ipsum aute voluptate. Dolore magna sint duis ipsum eu consectetur.\r\n", "balance": "$3,384.03", "name": "Jodie Collier", "gender": "female", "age": 27, "greeting": "Hello, Jodie Collier! You have 3 unread messages.", "longitude": 173.90763799999999, "_id": "58046a786230071a551569b9" }, { "guid": "badaf4d6-54fa-46e3-8a6d-6b6997483b00", "index": 1, "favoriteFruit": "strawberry", "latitude": 39.709885, "company": "DRAGBOT", "email": "alstonmays@dragbot.com", "picture": "http://placehold.it/32x32", "tags": [ "elit", "ea", "ipsum", "velit", "amet", "laborum", "duis" ], "registered": "2016-06-01T05:06:26 -06:00", "eyeColor": "green", "phone": "+1 (911) 423-3011", "address": "248 Forbell Street, Mathews, Vermont, 4994", "friends": [ { "id": 0, "name": "Liza Day" }, { "id": 1, "name": "Catherine Palmer" }, { "id": 2, "name": "Beryl Conway" } ], "isActive": false, "about": "Proident id fugiat pariatur et incididunt commodo est irure in duis ullamco veniam est magna. Id enim qui commodo exercitation labore adipisicing excepteur adipisicing dolor veniam. Qui quis minim commodo mollit est sit.\r\n", "balance": "$1,375.60", "name": "Alston Mays", "gender": "male", "age": 33, "greeting": "Hello, Alston Mays! You have 10 unread messages.", "longitude": -67.445130000000006, "_id": "58046a78a50c13da27ab0d11" }, { "guid": "e328c11c-f948-42a6-aede-179ec44a7873", "index": 2, "favoriteFruit": "apple", "latitude": 17.807843999999999, "company": "INSOURCE", "email": "cassandramcintyre@insource.com", "picture": "http://placehold.it/32x32", "tags": [ "et", "anim", "dolor", "magna", "quis", "occaecat", "dolor" ], "registered": "2015-09-11T03:36:24 -06:00", "eyeColor": "blue", "phone": "+1 (865) 558-2301", "address": "189 Cranberry Street, Riverton, Arkansas, 5369", "friends": [ { "id": 0, "name": "Whitley Howe" }, { "id": 1, "name": "Roseann Perez" }, { "id": 2, "name": "Sasha Richard" } ], "isActive": false, "about": "Consequat adipisicing ut dolor in. Id enim consectetur qui incididunt non amet laboris. Veniam amet dolore proident est proident dolor sunt nulla est quis veniam commodo anim. Ut exercitation excepteur enim quis et ea veniam non laboris duis. Dolore cillum commodo dolore reprehenderit aliqua labore.\r\n", "balance": "$3,678.92", "name": "Cassandra Mcintyre", "gender": "female", "age": 29, "greeting": "Hello, Cassandra Mcintyre! You have 8 unread messages.", "longitude": 93. 

Whole log

 10/17 16:38:54: Launching app Cold swapped changes. $ adb shell am start -n "lutmobile.com.chatforclash/lutmobile.com.chatforclash.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER Connected to process 20027 on device Nexus_5X_API_22 [emulator-5554] I/InstantRun: Instant Run Runtime started. Android package is lutmobile.com.chatforclash, real application class is null. W/art: Failed to find OatDexFile for DexFile /data/data/lutmobile.com.chatforclash/files/instant-run/dex/slice-slice_2-classes.dex ( canonical path /data/data/lutmobile.com.chatforclash/files/instant-run/dex/slice-slice_2-classes.dex) with checksum 0x115b7e55 in OatFile /data/data/lutmobile.com.chatforclash/cache/slice-slice_2-classes.dex D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization. D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization. I/FA: App measurement is starting up, version: 9683 I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE D/FA: Debug-level message logging enabled D/FA: AppMeasurement singleton hash: 323582673 V/FA: Collection enabled V/FA: App package, google app id: lutmobile.com.chatforclash, 1:289646024129:android:828d73aeecfbef22 I/FA: To enable faster debug mode event logging run: adb shell setprop firebase.analytics.debug-mode lutmobile.com.chatforclash V/FA: Registered activity lifecycle callback I/FirebaseInitProvider: FirebaseApp initialization successful V/FA: Using measurement service V/FA: Connecting to remote service W/GooglePlayServicesUtil: Google Play services out of date. Requires 9683000 but found 9452280 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable V/FA: onActivityCreated V/FA: Activity resumed, time: 1378725 D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true [ 10-17 10:38:54.848 20027:20027 D/ ] HostConnection::get() New Host Connection established 0x7f2075546740, tid 20027 D/Atlas: Validating map... W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null} [ 10-17 10:38:54.920 20027:20072 D/ ] HostConnection::get() New Host Connection established 0x7f207840cec0, tid 20072 I/OpenGLRenderer: Initialized EGL, version 1.4 D/OpenGLRenderer: Enabling debug mode 0 W/EGL_emulation: eglSurfaceAttrib not implemented W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f207851a540, error=EGL_SUCCESS V/FA: Activity paused, time: 1382044 V/FA: onActivityCreated V/FA: Activity resumed, time: 1382080 W/EGL_emulation: eglSurfaceAttrib not implemented W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f2075546dc0, error=EGL_SUCCESS D/OpenGLRenderer: endAllStagingAnimators on 0x7f20755b2800 (RippleDrawable) with handle 0x7f20784bc660 W/EGL_emulation: eglSurfaceAttrib not implemented W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f20755925c0, error=EGL_SUCCESS V/RenderScript: 0x7f207863d000 Launching thread(s), CPUs 2 D/Result:: [ { "guid": "fdaefcc1-6469-4e3a-9d03-722f8de768d9", "index": 0, "favoriteFruit": "banana", "latitude": 52.644930000000002, "company": "DECRATEX", "email": "jodiecollier@decratex.com", "picture": "http://placehold.it/32x32", "tags": [ "esse", "tempor", "fugiat", "labore", "eu", "aliquip", "fugiat" ], "registered": "2015-06-07T09:21:48 -06:00", "eyeColor": "blue", "phone": "+1 (870) 541-3015", "address": "503 Rugby Road, Defiance, Alaska, 2923", "friends": [ { "id": 0, "name": "Melton Reese" }, { "id": 1, "name": "Sara Gilbert" }, { "id": 2, "name": "Nicholson Weber" } ], "isActive": false, "about": "Fugiat Lorem mollit in pariatur incididunt est cupidatat veniam sit officia. Dolor dolor velit ex fugiat dolore officia enim quis in pariatur do ea. Ipsum cillum duis aliquip ut occaecat qui sint est aliqua consequat reprehenderit non. Velit pariatur aute voluptate minim in deserunt amet duis laborum laborum amet. Fugiat nostrud culpa ipsum Lorem proident pariatur aliqua fugiat culpa. Et aliquip magna exercitation ipsum aute voluptate. Dolore magna sint duis ipsum eu consectetur.\r\n", "balance": "$3,384.03", "name": "Jodie Collier", "gender": "female", "age": 27, "greeting": "Hello, Jodie Collier! You have 3 unread messages.", "longitude": 173.90763799999999, "_id": "58046a786230071a551569b9" }, { "guid": "badaf4d6-54fa-46e3-8a6d-6b6997483b00", "index": 1, "favoriteFruit": "strawberry", "latitude": 39.709885, "company": "DRAGBOT", "email": "alstonmays@dragbot.com", "picture": "http://placehold.it/32x32", "tags": [ "elit", "ea", "ipsum", "velit", "amet", "laborum", "duis" ], "registered": "2016-06-01T05:06:26 -06:00", "eyeColor": "green", "phone": "+1 (911) 423-3011", "address": "248 Forbell Street, Mathews, Vermont, 4994", "friends": [ { "id": 0, "name": "Liza Day" }, { "id": 1, "name": "Catherine Palmer" }, { "id": 2, "name": "Beryl Conway" } ], "isActive": false, "about": "Proident id fugiat pariatur et incididunt commodo est irure in duis ullamco veniam est magna. Id enim qui commodo exercitation labore adipisicing excepteur adipisicing dolor veniam. Qui quis minim commodo mollit est sit.\r\n", "balance": "$1,375.60", "name": "Alston Mays", "gender": "male", "age": 33, "greeting": "Hello, Alston Mays! You have 10 unread messages.", "longitude": -67.445130000000006, "_id": "58046a78a50c13da27ab0d11" }, { "guid": "e328c11c-f948-42a6-aede-179ec44a7873", "index": 2, "favoriteFruit": "apple", "latitude": 17.807843999999999, "company": "INSOURCE", "email": "cassandramcintyre@insource.com", "picture": "http://placehold.it/32x32", "tags": [ "et", "anim", "dolor", "magna", "quis", "occaecat", "dolor" ], "registered": "2015-09-11T03:36:24 -06:00", "eyeColor": "blue", "phone": "+1 (865) 558-2301", "address": "189 Cranberry Street, Riverton, Arkansas, 5369", "friends": [ { "id": 0, "name": "Whitley Howe" }, { "id": 1, "name": "Roseann Perez" }, { "id": 2, "name": "Sasha Richard" } ], "isActive": false, "about": "Consequat adipisicing ut dolor in. Id enim consectetur qui incididunt non amet laboris. Veniam amet dolore proident est proident dolor sunt nulla est quis veniam commodo anim. Ut exercitation excepteur enim quis et ea veniam non laboris duis. Dolore cillum commodo dolore reprehenderit aliqua labore.\r\n", "balance": "$3,678.92", "name": "Cassandra Mcintyre", "gender": "female", "age": 29, "greeting": "Hello, Cassandra Mcintyre! You have 8 unread messages.", "longitude": 93. W/FA: Tasks have been queued for a long time 

  • 2
    int len = 500 you yourself say that 500 characters downloaded. 500 characters in your answer - Senior Pomidor
  • By the way, yes, and it also tried. How to determine the length of the request? just if you specify well NNNN, then come to the similarity of the answer "company": "DRAGBOT", "email": "alstonmays@dragbot.com", "pict - Injection
  • Well, or how to specify what would load all the content. The code is copied from the office. Documentation - Injection
  • remove the 500 character limit, read everything from the stream and close the InputStream immediately after that - Sergi
  • Wildly uncomfortable. I only study therefore the realization of your advice, I don’t really understand it. I turn from php: (If not difficult, they could not poke a finger - Injection

1 answer 1

The problem is that you yourself say that 500 characters download int len = 500
there are 500 characters in your answer

An example of reading the stream.

  BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuilder out = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { out.append(line); } System.out.println(out.toString()); //Prints the string content read from input stream reader.close(); 
  • Thanks for the code, as I wrote above, I did it the same way. And in fact, a situation arose, because of which the whole problem arose. This code loads only the first 4066 characters. There are no others. - Injection
  • @ user3331078 is very strange, update the question and attach your new output - Senior Pomidor
  • Updated. I am here for the first time, so in parallel I try to figure out how to work here)) - Injection
  • about 4066 characters, IOException is not caused by you? Can the connection be broken? check it please - Senior Pomidor
  • Changed the code, to more optimized, in the logs after the output of the result only this W/FA: Tasks have been queued for a long time - Injection