Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CloseableHttpClient client = HttpClients.createDefault();
- HttpPost httpPost = new HttpPost("https://ca8bd50035014df99faf0dabb296bf37.westeurope.azure.elastic-cloud.com:9243/big-data-con/_doc/60");
- httpPost.setHeader("content-type", "application/json");
- httpPost.setHeader("Authorization", "Basic ZWxhc3RpYzp4UEZoY2ZRazNZbVYzTWM5azlIWDZnNTI=");
- String json = "{\n" +
- "\"timestamp\": \"2020-01-25T20:30:32Z\",\n" +
- "\"humididy\": 22,\n" +
- "\"temperature\": 25,\n" +
- "\"pressure\": 190,\n" +
- "\"noice\": 85\n" +
- "}";
- StringEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- params.add(new BasicNameValuePair("timestamp","2020-01-25T20:10:32Z"));
- params.add(new BasicNameValuePair("humididy","22"));
- params.add(new BasicNameValuePair("temperature","25"));
- params.add(new BasicNameValuePair("pressure","190"));
- params.add(new BasicNameValuePair("noice","85"));
- httpPost.setEntity(stringEntity);
- // httpPost.setEntity(new UrlEncodedFormEntity());
- CloseableHttpResponse response = client.execute(httpPost);
- System.out.println(response.getStatusLine());
- String content = EntityUtils.toString(response.getEntity());
- System.out.println(content);
- client.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement