cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problems with site-download

From: Peter Staab <PixStaMP_at_gmx.net>
Date: Sat, 3 Sep 2005 12:47:02 +0200 (MEST)

Hello,

I use the two functions below to download websites into a char*. Everything
works fine for many sites but sometimes, e.g. when a €-sign (EURO-Sign) or
some other special character occurs, the download cancels before this sign
(without a error) and I only get the website's content til this position.

Where could the bug be?

Thank you,
Peter

struct memory{
                char *content;
                long size;
        };

void IThread::loadData(char *loc)
{
        CURL *curl;
        CURLcode res;

        curl = curl_easy_init();
        if(curl) {
                curl_easy_setopt(curl, CURLOPT_URL, loc);
                
                curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
                curl_easy_setopt(curl, CURLOPT_TIMEOUT, params->timeout);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, IThread::parse_data);
                curl_easy_setopt(curl, CURLOPT_FILE, (void *)&xml);

                curl_easy_perform(curl);

                
                xmli = &xml;

                curl_easy_cleanup(curl);
        }
}

int IThread::parse_data(void *ptr, int size, int nmemb, void *data) {
        register int realsize = size * nmemb;
        struct memory *mem = (struct memory *)data;
        mem->content = (char *)realloc(mem->content, mem->size + realsize + 1);

        if (mem->content) {
                memcpy(&(mem->content[mem->size]), ptr, realsize);
                mem->size += realsize;
                mem->content[mem->size] = 0;
        }

        return realsize;
}

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
Received on 2005-09-03