cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Newbie Question...

From: LI,CHARLES (Non-HP-Roseville,ex1) <charles_li_at_non.hp.com>
Date: Mon, 11 Jun 2001 13:39:23 -0400

listmail_at_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_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library

_______________________________________________
Curl-library mailing list
http://curl.haxx.se/libcurl/
Received on 2001-06-11