cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How can i get the answer from a post ?

From: Jabka Atu <mashrom.head_at_gmail.com>
Date: Sun, 27 Jul 2008 18:16:17 +0300

On Sun, Jul 27, 2008 at 5:23 PM, Joe N. <jnardone_at_gmail.com> wrote:

>
> curl_easy_setopt(m_curl, CURLOPT_URL, url);
>> m_res = curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 1L);
>> m_res = curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION,write_to_buffer);
>> curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &buffer);
>> curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, data);
>> curl_easy_perform(m_curl);
>>
>> the function write_to_buffer appends all chars to string element (string
>> buffer).
>> data is a simple url post format (ex :
>>
>> "parent_pid=&format=text&code2=I+don't+know+how+to+get+answers+using+libcurl&poster=Jabka+Atu&paste=Send&expiry=m&email="
>>
>>
>>
> The POST response is in the buffer being written to by "write_to_buffer".
> If you aren't seeing it there, then there's probably something up in your
> buffer function.
>
> Joe

I used this function :

static size_t write_to_buffer(void *ptr, size_t size, size_t nmemb, void
*stream)
{
  if (stream == NULL)
     return 0;

  ((std::string *) stream)->append((const char *)ptr,size * nmemb);
  return size * nmemb;

}
and according to the samples (examples) it is preety close to it.
Received on 2008-07-27