7

I would like to send an http post request in c++. It seems like libcurl (Curlpp) is the way to go.

Now, here is a typical request that am sending

http://abc.com:3456/handler1/start?<name-Value pairs>

The name values pairs will have:

field1: ABC
field2: b, c, d, e, f
field3: XYZ

etc.

Now, I would like to know how to achieve the same using curlpp or libcurl. Code snippets will really help.

1 Answer 1

4

Don't have experience with Curlpp but this is how I did it with libcurl.

You can set your target url using

curl_easy_setopt(m_CurlPtr, CURLOPT_URL, "http://urlhere.com/");

POST values are stored in a linked list -- you should have two variables to hold the begin and the end of that list so that cURL can add a value to it.

struct curl_httppost* beginPostList;
struct curl_httppost* endPostList;

You can then add this post variable using

curl_formadd(&beginPostList, &endPostList, CURLFORM_COPYNAME, "key", CURLFORM_COPYCONTENTS, "value", CURLFORM_END);

Submitting then works like this

curl_easy_setopt(m_CurlPtr, CURLOPT_POST, true);
curl_easy_setopt(m_CurlPtr, CURLOPT_HTTPPOST, beginPostList); 
curl_easy_perform(m_CurlPtr);

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.