Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. CloseableHttpClient client = HttpClients.createDefault();
  2. HttpPost httpPost = new HttpPost("https://ca8bd50035014df99faf0dabb296bf37.westeurope.azure.elastic-cloud.com:9243/big-data-con/_doc/60");
  3.  
  4. httpPost.setHeader("content-type", "application/json");
  5. httpPost.setHeader("Authorization", "Basic ZWxhc3RpYzp4UEZoY2ZRazNZbVYzTWM5azlIWDZnNTI=");
  6.  
  7. String json = "{\n" +
  8. "\"timestamp\": \"2020-01-25T20:30:32Z\",\n" +
  9. "\"humididy\": 22,\n" +
  10. "\"temperature\": 25,\n" +
  11. "\"pressure\": 190,\n" +
  12. "\"noice\": 85\n" +
  13. "}";
  14. StringEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
  15.  
  16. List<NameValuePair> params = new ArrayList<NameValuePair>();
  17. params.add(new BasicNameValuePair("timestamp","2020-01-25T20:10:32Z"));
  18. params.add(new BasicNameValuePair("humididy","22"));
  19. params.add(new BasicNameValuePair("temperature","25"));
  20. params.add(new BasicNameValuePair("pressure","190"));
  21. params.add(new BasicNameValuePair("noice","85"));
  22. httpPost.setEntity(stringEntity);
  23. // httpPost.setEntity(new UrlEncodedFormEntity());
  24.  
  25. CloseableHttpResponse response = client.execute(httpPost);
  26. System.out.println(response.getStatusLine());
  27. String content = EntityUtils.toString(response.getEntity());
  28. System.out.println(content);
  29. client.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement