[prev in list] [next in list] [prev in thread] [next in thread] 

List:       curl-library
Subject:    RE: Newbie Question...
From:       "LI,CHARLES (Non-HP-Roseville,ex1)" <charles_li () non ! hp ! com>
Date:       2001-06-11 17:39:23
[Download RAW message or body]

listmail@cramnotch.com wrote:

> newbie question...  What's the easiest way to capture a returned web page
> in a string?  I've been playing with CURLOPT_WRITEFUNCTION but have not
> been very successful in my many attempts to save the data.  I don't want
> to write it to a file or anything -- I just want to shove it in a char *.

I did it by changing "size_t write_data(void *ptr, size_t size, size_t
nmemb, FILE *fst)"
from sample code. The function write_data() is set using
CURLOPT_WRITEFUNCTION.
Depending on you want receive response header and/or body, you use
"curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (FILE *)stdout);"
"curl_easy_setopt(curl_handle, CURLOPT_FILE, (FILE *)stdout);"
Since we don't want to save data into a file, I just pass "stdout", not
bother
define a file handler.

The trick is inside write_data() function. I don't write anything to "fst"
but
copy/append incoming data into a globe string. Whence blocked perform is
done,
I have all response data in the string. One more trick is I still need to
return size*nmemb in write_data(); without this, if the response data is
longer
than 2048, packages after the first chunk will be lost.

Enjoy!

Xiaojie Li
_______________________________________________
Curl-library mailing list
Curl-library@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic