Advertisement
Guest User

Untitled

a guest
Jan 12th, 2012
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. static void
  2. post_data(const char *to, const char *from, const char *data)
  3. {
  4.     CURL *curl;
  5.     long return_value;
  6.     CURLcode curl_return_value;
  7.     struct curl_httppost *first;
  8.     struct curl_httppost *last;
  9.     char error_buffer[CURL_ERROR_SIZE + 1] = { 0 };
  10.  
  11.     curl_global_init(CURL_GLOBAL_ALL);
  12.     curl = curl_easy_init();
  13.     VERIFY(curl != NULL);
  14.     curl_return_value = curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.104:8000/email");
  15.     VERIFY(curl_return_value == 0);
  16.     VERIFY(curl_formadd(&first, &last,
  17.             CURLFORM_PTRNAME, "to",
  18.             CURLFORM_PTRCONTENTS, to,
  19.             CURLFORM_END) == 0);
  20.     VERIFY(curl_formadd(&first, &last,
  21.             CURLFORM_PTRNAME, "from",
  22.             CURLFORM_PTRCONTENTS, from,
  23.             CURLFORM_END) == 0);
  24.     VERIFY(curl_formadd(&first, &last,
  25.             CURLFORM_PTRNAME, "data",
  26.             CURLFORM_PTRCONTENTS, data,
  27.             CURLFORM_END) == 0);
  28.     curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
  29.     curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  30.     curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
  31.  
  32.     curl_return_value = curl_easy_perform(curl);
  33.     if (curl_return_value == 0)
  34.     {
  35.         curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &return_value);
  36.         printf("Transfer returned %ld\n", return_value);
  37.     }
  38.     else
  39.     {
  40.         printf("curl_easy_perform returned %d\n", curl_return_value);
  41.         printf("%s\n", error_buffer);
  42.     }
  43.  
  44.     curl_formfree(first);
  45.  
  46.     curl_easy_cleanup(curl);
  47.     curl_global_cleanup();
  48.  
  49.     exit(0);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement