8

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?

2
  • Did you check out: curl.haxx.se/libcurl/c/postit2.html Kind regards, Bo Commented 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. Commented May 19, 2012 at 10:10

3 Answers 3

15
#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); } 
Sign up to request clarification or add additional context in comments.

3 Comments

How to do for submitting multipart/formdata?
How can I upload a file this way?
Post a question ?
8

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

I just want to submit a form using libcurl say i have to submit for acount creation on yahoo.com how should i do it? I dont want to upload a file but to submit a form.
K the generated code was using POSTFIELDS. But I wanted to submit a html form.
What exactly is the problem? The postfields as far as I can tell are the values you want to post.
K it also can be used.But how to do it using the function curl_formadd() ? I read that this function is basically used to submit form data to server. Example is given for uploading a file.And I want to use it to fill the form and submit it.
Why don't you try something and post back if you have a genuine problem? I haven't used libcurl myself and this is a suggestion based on my skimming of the documentation.
|
0

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

CODE GENERATOR in POSTMAN

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)

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.