There is a working code to connect to the server. You must set a timeout. urlconnection.setConnectTimeout () does not plow.

  URL url_groups = new URL("http://yarmiit.ru/index.php?name=ASU&op=apk&show_news"); urlConnection = (HttpURLConnection) url_groups.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuilder buffer = new StringBuilder(); reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { buffer.append(line); } resultJson = buffer.toString(); 

    1 answer 1

    Try setting urlconnection.setReadTimeout ()

    • The effect is the same. Waits more than a minute, then resets. Although set to 20 seconds. - zTrap
    • one
      You do not want to go at least to okHttp? ))) fewer problems will be easier in all respects, it will not be long to rewrite - Yury Pashkov
    • Consider this option, thank you. - zTrap
    • Here's a link to how it may look something like pastebin.com/6ms4yC9d in gson combination, respectively okhttp set a timeout - Yury Pashkov
    • and in the gradle dependencies compile "com.google.code.gson: gson: 2. +" compile 'com.squareup.okhttp: okhttp: 2.4.0' - Yury Pashkov