Domanda

vorrei inviare una richiesta HTTP Post in C ++. Sembra libcurl (Curlpp) è la strada da percorrere.

Ora, qui è una richiesta tipica che mando

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.

Ora, vorrei sapere come ottenere lo stesso utilizzando curlpp o libcurl. Frammenti di codice sarà di grande aiuto.

È stato utile?

Soluzione

non si ha esperienza con Curlpp ma questo è come ho fatto con libcurl.

È possibile impostare il vostro URL di destinazione utilizzando

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

??POST vengono memorizzate in una lista collegata -. si dovrebbe avere due variabili per contenere l'inizio e la fine di tale elenco in modo che cURL possibile aggiungere un valore ad esso

struct curl_httppost* beginPostList;
struct curl_httppost* endPostList;

È possibile aggiungere questa variabile post utilizzando

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

Invio quindi funziona come questo

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

Spero che questo aiuti!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top