cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Issues on callback write_data

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Fri, 23 Mar 2007 14:44:46 -0700

On Fri, Mar 23, 2007 at 06:07:04PM -0300, Gustavo Elias Siqueira wrote:
> Hi Fellows,
> I'm a beginner curl user, asking for a hand to solve a problem.
> When I call curl to perform, the libcurl at the
> first callback write_data, returns a buffer with 1100 and show a parcial
> data.For the second time, the buffer returns me 1768, but theres no data
> avaiable.

Where did you expect the data to be?

> // Crawler.cpp : main project file.
>
> #include <stdafx.h>
> #include <iostream>
> #include <curl/curl.h>
> #include <Threads.h>
>
> using namespace System;
>
> struct MemoryStruct {
> char *memory;
> size_t size;
> };
>
> size_t write_data(void *ptr, size_t size, size_t nmemb, void *data) {
> register int realsize = size * nmemb;
> struct MemoryStruct *mem = (struct MemoryStruct *)data;

You're using a pointer (data) that has never been set in your program.
It's just going to contain garbage, if anything. You need to allocate
space for your MemoryStruct structure somewhere and pass in the pointer
using the CURLOPT_WRITEDATA option. Then, after curl_easy_perform
returns, you use the same pointer to access the downloaded data.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2007-03-23