Skip to content

Instantly share code, notes, and snippets.

@joewilliams
Created September 9, 2010 17:06
Show Gist options
  • Save joewilliams/572182 to your computer and use it in GitHub Desktop.
Save joewilliams/572182 to your computer and use it in GitHub Desktop.
/*
mostly stolen from:
http://github.com/bagder/curl/blob/master/docs/examples/http-post.c
to compile:
gcc -lcurl post.c -o post
*/
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
struct curl_slist *headerlist=NULL;
char *url;
char *data;
url = "http://localhost:5984/joe";
data = "{\"test\":\"test\"}";
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
headerlist = curl_slist_append(headerlist, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment