cURL / Mailing Lists / curl-library / Single Mail


Problem in receiving the compressed data

From: Shailesh Mittal <>
Date: Thu, 8 Nov 2001 11:05:44 -0800 (PST)


I am have the same old problem in receiving the
compressed data from a Servlet running on tomcat.

Initially, I was trying to receive the body data in
memory (used the sample getinmemory.c) and coded the
callback function as

size_t WriteMemoryCallback(void *ptr, size_t size,
size_t nmemb, void *data)
    register int realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct

    mem->memory = (char *)realloc(mem->memory,
mem->size + realsize + 1);
    if (mem->memory) {
        memcpy(&(mem->memory[mem->size]), ptr,
        mem->size += realsize;
        mem->memory[mem->size] = 0;
    return realsize;
I was getting NO data other than "||||" in the "void
*ptr". Interestingly the value of
(size * nmemb) is around 270. Where is the data to be
uncompressed? I have to pass the
compressed data to a function so than I can uncompress

I then switched to dumping the data into a file (code
listing below) instead of capturing it in memory. This
time I get the compressed data but it is not complete.
On uncompressing the file, I get only half of the XML
document. Why I am not getting the complete data?

I will appreciate if somebody can help me in capturing
the complete compressed data in memory.

size_t WriteBodyCallback(void *ptr, size_t size,
size_t nmemb, void *stream)
   size_t written = fwrite(ptr, size, nmemb, (FILE
   return written;

BOOL CallServlet_b ()
    FILE *bodyFile;
    bodyFile = fopen(SCRIBE_COMPRESS_FILENAME,"w");

    CURL *m_curl = curl_easy_init();

    curl_slist *m_headerDataList =

    curl_easy_setopt(m_curl, CURLOPT_URL,

    if (m_headerDataList)
       curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER,

    curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION,
    curl_easy_setopt(m_curl, CURLOPT_FILE, bodyFile);


    fclose (bodyFile);

On the server, the code is simple. Listing below,

    response.setHeader("Content-Encoding", "gzip");

        out = new PrintWriter(new
GZIPOutputStream(response.getOutputStream()), false);

        out.println("XML Data to be compressed");

Some more information about the problem,
1. I used curl.exe and able to see the compressed
2. I accessed the URL thru IE. It uncompressed the
data and displayed the actual XML.

I have implemented all previous suggestiuons but could
not make it work.


Do You Yahoo!?
Find a job, post your resume.
Received on 2001-11-08