curl-library
Re: How to retrieve webpage from curl_easy_perform
Date: Tue, 03 Mar 2015 11:55:31 -0500
Specifically, I replaced the READFUNCTION and READDATA with
WRITEFUNCTION and WRITEDATA respectively. At first I changed the
callback function to this:
static size_t read_callback(void *ptr, size_t size, size_t nmemb,
void *stream)
{
curl_off_t nread;
char *r = (char*)ptr;
size_t retcode = fwrite(r, size, nmemb, (FILE*)stream);
nread = (curl_off_t)retcode;
return retcode;
}
When I ran that, it would get the curl_easy_perform call, then the
program would freeze and crash. When I tried replacing the contents of
the callback function with this test:
fprint("%s.*", size, (char*)stream);
return 0;
It gave me the error code 23 I mentioned before.
On 3/3/2015 11:46 AM, Josh Angstadt wrote:
> Hi, I tried to use the write options as well, but when I used those I
> got an error from the connection, speciifcally error code 23
>
> On 3/3/2015 11:40 AM, Patrick Monnerat wrote:
>> Josh Angstadt wrote:
>>> curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
>>> curl_easy_setopt(curl, CURLOPT_READDATA, result);
>> Your program is supposed to DOWNLOAD, isn't it ?
>>
>> The http://curl.haxx.se/libcurl/c/CURLOPT_READFUNCTION.html specifies:
>>
>> CURLOPT_READFUNCTION - read callback for data UPLOADS.
>>
>> You probably need to use
>> http://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html instead.
>>
>> If you just want to write received data to a file, use CURLOPT_WRITEDATA
>> with the preopened FILE * (CURLOPT_WRITEFUNCTION is set to fwrite by
>> default).
>> If you want to process data before writing it somewhere, please see
>> example http://curl.haxx.se/libcurl/c/getinmemory.html
>>
>> -------------------------------------------------------------------
>> List admin: http://cool.haxx.se/list/listinfo/curl-library
>> Etiquette: http://curl.haxx.se/mail/etiquette.html
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-03-03