Skip to content

Instantly share code, notes, and snippets.

@mfine
Created June 22, 2017 18:59
Show Gist options
  • Save mfine/f98c32e8bbe11f57896388548683433a to your computer and use it in GitHub Desktop.
Save mfine/f98c32e8bbe11f57896388548683433a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <curl/curl.h>
size_t download_write(char *buf, size_t size, size_t n, void *data)
{
return fwrite(buf, size, n, stdout);
}
size_t upload_read(char *buf, size_t size, size_t n, void *data)
{
printf("XXXXXX READING!!!\n");
return 0;
}
int main(void)
{
CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
if (code != CURLE_OK) {
return -1;
}
CURL *curl = curl_easy_init();
if (curl == NULL) {
return -1;
}
struct curl_slist *chunk = NULL;
chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "my-client/1.0");
curl_easy_setopt(curl, CURLOPT_URL, "myurl");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_write);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, upload_read);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
code = curl_easy_perform(curl);
if (code != CURLE_OK) {
return -1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment