cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: (no subject)

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Tue, 10 Apr 2001 10:40:06 +0200 (MET DST)

On 10 Apr 2001, Gilles Talbot wrote:

> i would like to know if it's possible to have the result of a request
> made with curl_easy _perform in a string instead of having it in a file.

You could try having a look at paragraph 5.2 in the FAQ, found at
http://curl.haxx.se/docs/faq.shtml

  5.2 How can I receive all data into a large memory chunk?

  You are in full control of the callback function that gets called every
  time there is data received from the remote server. You can make that
  callback do whatever you want. You do not have to write the receivied data
  to a file.

  One solution to this problem could be to have a pointer to a struct that
  you pass to the callback function. You set the pointer using the
  curl_easy_setopt(CURLOPT_FILE) function. Then that pointer will be passed
  to the callback instead of a FILE * to a file:

        /* imaginary struct */
        struct MemoryStruct {
          char *memory;
          size_t size;
        };

        /* imaginary callback function */
        size_t
        WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
        {
          register int realsize = size * nmemb;
          struct MemoryStruct *mem = (struct MemoryStruct *)data;

          mem->memory = (char *)realloc(mem->memory, mem->size + realsize +
                        1);
          if (mem->memory) {
            memcpy(&(mem->memory[mem->size]), ptr, realsize);
            mem->size += realsize;
            mem->memory[mem->size] = 0;
          }
          return realsize;
        }

-- 
  Daniel Stenberg -- curl project maintainer -- http://curl.haxx.se/
_______________________________________________
Curl-library mailing list
Curl-library_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library
Received on 2001-04-10