I apologize in advance if this turns out to be an incorrect code, but nothing was better to “collect”.

DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet( "http:"); getRequest.setHeader("Accept", "application/json"); // Use GZIP encoding getRequest.setHeader("Accept-Encoding", "gzip"); // try { HttpResponse response = (HttpResponse) httpclient .execute(getRequest); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); Header contentEncoding = response .getFirstHeader("Content-Encoding"); if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) { instream = new GZIPInputStream(instream); } // convert content stream to a String String result = readStream(instream); instream.close(); Log.i("JSON", result); TextView view = (TextView) findViewById(R.id.result); view.setText(result); JSONObject jsonObject = new JSONObject(result); } } catch (Exception e) { e.printStackTrace(); } } private static String readStream(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } 

I do not understand the reason. If IT can be corrected, tell me where to change. If not, then I have specific questions that I could not find anything intelligible ...
Thank you in advance!

  • one
    format the code, for starters - Stas0n
  • 2
    what to fix? where are the mistakes? - Gorets
  • Yes, there are not enough logs ... - Stas0n
  • launching has encountered error occurred during the build - s01nyshko 2:42
  • Gorets? Thanks for the correction! - s01nyshko 2:46

1 answer 1

Wash you are looking for this:

 public XMLParser() {} public String getXmlFromUrl(String url) { String xml = null; try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); xml = EntityUtils.toString(httpEntity); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // return XML return xml; } 

This is a completely working code.

  • Kerins_Sataier, replaced only Post with Get, does not work, writes the same thing when trying to start. In Manifeste, what is a special thread to prescribe? - s01nyshko
  • Internet rights - Gorets
  • How long ??? I put on AsyncTask - rasmisha
  • Gorets, the rights are registered. rasmisha, what exactly dock AsyncTask, in the sense you think that without it it does not start ??? And what is not possible to realize all this in stages? - s01nyshko
  • Try what is described here veryant.com/support/phpkb/question.php?ID=157 - Kerins_Sataier