public void getResponse ( StringBuilder sb ) throws IOException { // checks server's status code first int status = mHttpURLConnection . getResponseCode ( ) ; if ( status == HttpURLConnection . HTTP_OK ) { InputStream ips = new BufferedInputStream ( mHttpURLConnection . getInputStream ( ) ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( ips , "UTF-8" ) ) ; char [ ] buffer = new char [ 1024 ] ; int bufferLength ; while ( ( bufferLength = reader . read ( buffer , 0 , buffer . length ) ) > 0 ) { sb . append ( buffer , 0 , bufferLength ) ; } reader . close ( ) ; ips . close ( ) ; mHttpURLConnection . disconnect ( ) ; } else { throw new IOException ( "Server returned non-OK status: " + status ) ; } }
Completes the request and receives response from the server .