http://www.linuxdevcenter.com/pub/a/linux/2005/05/05/libcurl.html
http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
libcURL is a open source library that help handle network connection. To write a binary post program, the sequence is as follows:
//general initilization
CURL* ctx = curl_easy_init();
//set URL
curl_easy_setopt(ctx, CURLOPT_URL, "http://WebsiteYouDesire.com");
//set POST method
curl_easy_setopt(ctx, CURLOPT_POST,1);
//give the data you want to post
curl_easy_setopt(ctx, CURLOPT_POSTFIELDS, pd);
//show messages for debugging
curl_easy_setopt(ctx, CURLOPT_VERBOSE);
//set the callback function that handle the data return from server
//if you don't set this, the return data just show up on the screen
//size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp)
curl_easy_setopt(ctx, CURLOPT_WRITEFUNCTION, write_callback);
//talor the header to application/binary
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/binary");
curl_easy_setopt(ctx, CURLOPT_HTTPHEADER, headers);
//let's do it...
CURLcode ret = curl_easy_perform(ctx);
//clean up
curl_slist_free_all(headers);
curl_easy_cleanup(ctx);
After all these, you will see some information on the screen. and the return data from server.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment