Advertisement
Guest User

Untitled

a guest
Nov 7th, 2012
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. extern "C" {
  5.     #include <curl/curl.h>
  6. }
  7. int main() {
  8.     CURL *curl_handle;
  9.     CURLcode res;
  10.  
  11.     static const char *postthis="{\"size\":100000,\"query\":{\"range\":{\"snapshotTime\":{\"from\":\"2012-10-31T13:00:00\",\"to\":\"2012-10-31T14:00:00\"}}}}";
  12.     curl_global_init(CURL_GLOBAL_ALL);
  13.     curl_handle = curl_easy_init();
  14.  
  15.     if(curl_handle) {
  16.         curl_easy_setopt(curl_handle, CURLOPT_URL, "http://localhost:9202/_all/_search");
  17.         curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postthis);
  18.        
  19.         curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
  20. //        curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
  21.         curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, stdout);
  22.         curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, stdout);
  23.  
  24.         res = curl_easy_perform(curl_handle);
  25.         if(res != CURLE_OK)
  26.                   fprintf(stderr, "curl_easy_perform() failed: %s\n",
  27.                                         curl_easy_strerror(res));
  28.         curl_easy_cleanup(curl_handle);
  29.         return 0;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement