Response Entity HttpClient

0

I request your collaboration due to the fact that I am consuming information from a website and I do not know what the problem is that is generating me, because in some requests I can do String mensaje = EntityUtils.toString(entity); and it works, but I just made the implementation for another method and I can not do it anymore, I get the following: java.io.IOException: Attempted read from closed stream. ; the implementation in the following:

public void buscarRadicado(HttpClient httpclient, HttpPost httpost) throws Exception
    {
        List <NameValuePair> nameValuePair = null;
        HttpResponse response = null;
        HttpEntity entity = null;

        try 
        {
            {
                for(int index = 0; index < 10 ; ++index )
                {
                    httpost = new HttpPost("path");
                    // Parametros de la consulta
                    nameValuePair = new ArrayList <NameValuePair>();
                    nameValuePair.add(new BasicNameValuePair("submit", "CONSULTAR"));
                    nameValuePair.add(new BasicNameValuePair("cod_tipo", "25"));
                    nameValuePair.add(new BasicNameValuePair("no_int", 123456));
                    nameValuePair.add(new BasicNameValuePair("uno", ""));

                    httpost.setEntity(new UrlEncodedFormEntity(nameValuePair, Consts.UTF_8));
                    response = response = httpclient.execute(httpost);
                    entity = response.getEntity();
                    mensaje = EntityUtils.toString(entity);
                    EntityUtils.consume(entity);
                    entity = null;
                    httpost = null;
                    response = null;
                    guardarMensaje(mensaje);
                    mensaje = "se guardo Correctamente";
            }
        }
        catch (ClientProtocolException e) 
        {
            httpost.releaseConnection();
            httpclient.getConnectionManager().shutdown();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
            httpost.releaseConnection();
            httpclient.getConnectionManager().shutdown();
        }
    }

Response code: response.getStatusLine().getStatusCode() 200

Content-Type: response.getEntity().getContentType(); text / html

    
asked by Gdaimon 15.10.2018 в 23:30
source

1 answer

0

entity = response.getEntity (); returns a null value since it has no information in the class. If you want to have a value you need response.setEntity ()

    
answered by 15.10.2018 в 23:56