Pergunta

i am trying to get the response from a url like it is (with whitespace included ) but the whitespaces are always deleted . this is my code

HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(link); 
            HttpResponse httpResponse;
            httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();       

            String  s = EntityUtils.toString(httpEntity, HTTP.UTF_8);

            String[] ar = s.split(" ");
            Log.e("responsesize" , String.valueOf(ar.length));
            for(int i =0 ; i < ar.length ; ++i)
            {
                Log.e("response" , ar[i]);
            }

my response is : TRYING2020/1/12014/04/1103 but it should be :

TRYING 2020/1/1 2014/04/11 0    3

any idea how to do this ? ( sry if this is stupid but tried to find a post on it but evthg i c is removing whitespaces from url not keeping from response )

Foi útil?

Solução 2

found it . actually i thought that a tab was a combination of 4 spaces ... so if i split with spaces i get one array.But spliting with tabs gives me the response

Outras dicas

Try this way

try{

                StringBuffer sb = new StringBuffer();
                URL url = new URL(location);
                urlConnection = (HttpURLConnection) url.openConnection();

                BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line + "\n");
                }
                return sb.toString();
            }  
    finally {
                urlConnection.disconnect();
            }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top