Pregunta

Me gustaría enviar una solicitud HTTP POST en C ++. Parece que libcurl (Curlpp) es el camino a seguir.

Ahora, aquí hay una petición típico que estoy enviando

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.

Ahora, me gustaría saber cómo lograr lo mismo usando curlpp o libcurl. Los fragmentos de código realmente ayudará.

¿Fue útil?

Solución

no tienen experiencia con Curlpp pero así es como lo hice con libcurl.

Puede configurar su URL de destino utilizando

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

POST se almacenan en una lista enlazada -. usted debe tener dos variables para contener el inicio y el final de esa lista, de modo que se curvan puede agregar un valor a la misma

struct curl_httppost* beginPostList;
struct curl_httppost* endPostList;

A continuación, puede agregar esta variable posteriormente utilizando

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

Presentar a continuación, funciona de la siguiente

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

Espero que esto ayude!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top