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?
- Did you check out: curl.haxx.se/libcurl/c/postit2.html Kind regards, BoBo.– Bo.2012-05-18 10:18:26 +00:00Commented May 18, 2012 at 10:18
- Yes I checked it but it is given for uploading a file I have to use it for submitting form I m not getting it clearly how it can be done.Shraddha K– Shraddha K2012-05-19 10:10:57 +00:00Commented May 19, 2012 at 10:10
3 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); } 3 Comments
Refer the manual page for documentation the -d option. You can use that multiple times to pass different key,value pairs to the server. Once that works, use the --libcurl flag to see what it would look like if you're trying to use libcurl to manually do this in your application.
9 Comments
libcurl myself and this is a suggestion based on my skimming of the documentation.This is to share my experience in development of REST clients using libcurl and I found a very easy way to find out the code snippets for ANY REST call using POSTMAN in MANY LANGUAGES. And it really worked for me!!! Install POSTMAN and the check there's a button called 'Code' on the right side (I used this on windows only, but should work for other OS as well as libcurl is portable across many operating systems)
If anyone wants to read the documentation and examples it could be found here. https://curl.haxx.se/docs/faq.html#What_is_cURL
You can find the correct code snippets using libcurl for the languages supported in the left pane. C, C#, PHP, Python, Java, Java script etc...
Best thing is you can test your call from POSTMAN and at the same time can find the right code snippet and the curl command to use from command prompt as well (If you select cURL from left pane)

