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 someone 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);
}
How is the loop structure done? Without the loop, it is difficult to guess what is happening in the execution flow control
– Jefferson Quesado
is one of the normal while(true), to send eternally
– user115863
I edited the code to be more complete, but I’ve already been downvoted :c
– user115863
clientClose
is instantiated once and closed several times? And is not used once if you want before being closed?– Jefferson Quesado