Why does my Client only send two requests?

1

My HttpClient is only sending two requests. The server receives, returns the 2 values but it is actually a loop that sends a lot of times! Can anyone help me?

public static void main(String[] args) throws IOException, InterruptedException {
    SendData sender = new SendData();
    String JsonDeDados;
    String infos = "informacoes";

    HttpClient client = HttpClientBuilder.create().build();
    CloseableHttpClient clientclose = HttpClients.createDefault();
    HttpPost post = new HttpPost("http://localhost:5030/data");

    do {

        JsonDeDados = sender.sendMessageDATA();
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair(infos, JsonDeDados));
        StringEntity entity = new StringEntity(JsonDeDados);

        post.setEntity(entity);
        post.setHeader("Content-Type", "application/json");

        CloseableHttpResponse response = (CloseableHttpResponse) client.execute(post);
        System.out.println("Código da Resposta: " + response.getStatusLine().getStatusCode());
        clientclose.close();
        Thread.sleep(1000);

    }while(true);

}
    
asked by anonymous 12.06.2018 / 18:55

1 answer

1

I think the .releaseConnection(); command might be missing from your HttpPost. Possibly it will stay:

post.releaseConnection();

Try this, if it is not, it may be something in your loop repetition

    
12.06.2018 / 19:05