Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void
- post_data(const char *to, const char *from, const char *data)
- {
- CURL *curl;
- long return_value;
- CURLcode curl_return_value;
- struct curl_httppost *first;
- struct curl_httppost *last;
- char error_buffer[CURL_ERROR_SIZE + 1] = { 0 };
- curl_global_init(CURL_GLOBAL_ALL);
- curl = curl_easy_init();
- VERIFY(curl != NULL);
- curl_return_value = curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.104:8000/email");
- VERIFY(curl_return_value == 0);
- VERIFY(curl_formadd(&first, &last,
- CURLFORM_PTRNAME, "to",
- CURLFORM_PTRCONTENTS, to,
- CURLFORM_END) == 0);
- VERIFY(curl_formadd(&first, &last,
- CURLFORM_PTRNAME, "from",
- CURLFORM_PTRCONTENTS, from,
- CURLFORM_END) == 0);
- VERIFY(curl_formadd(&first, &last,
- CURLFORM_PTRNAME, "data",
- CURLFORM_PTRCONTENTS, data,
- CURLFORM_END) == 0);
- curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
- curl_return_value = curl_easy_perform(curl);
- if (curl_return_value == 0)
- {
- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &return_value);
- printf("Transfer returned %ld\n", return_value);
- }
- else
- {
- printf("curl_easy_perform returned %d\n", curl_return_value);
- printf("%s\n", error_buffer);
- }
- curl_formfree(first);
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement