Advertisement
Guest User

Untitled

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