Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use libcurl for HTTP post?

Tags:

c

libcurl

I am new using libcurl. I am not understanding clearly how to use it for HTTP POST requests and how to check the result. How can I use it for this?

like image 948
Shraddha K Avatar asked May 18 '12 10:05

Shraddha K


1 Answers

#include <curl/curl.h>
main()
{
  CURL *curl;
  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/hello-world");
  curl_easy_setopt(curl, CURLOPT_POST, 1);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "foo=bar&foz=baz");
  curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}
like image 80
kmkaplan Avatar answered Oct 26 '22 03:10

kmkaplan