cURL / Mailing Lists / curl-library / Single Mail

curl-library

Problem in receiving the compressed data

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

Hello,

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
*)data;

    mem->memory = (char *)realloc(mem->memory,
mem->size + realsize + 1);
    if (mem->memory) {
        memcpy(&(mem->memory[mem->size]), ptr,
realsize);
        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
it.

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
*)stream);
   return written;
}

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

    CURL *m_curl = curl_easy_init();

    curl_slist *m_headerDataList =
curl_slist_append(m_headerDataList,
"Accept-Encoding:gzip");

    curl_easy_setopt(m_curl, CURLOPT_URL,
"http://....");

    if (m_headerDataList)
    {
       curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER,
m_headerDataList);
    }

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

    curl_easy_perform(m_curl);

    fclose (bodyFile);
    
    curl_easy_cleanup(m_curl);
}

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

    response.setHeader("Content-Encoding", "gzip");
        response.setContentType("text/plain");

        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
data.
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.

Shailesh.

__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com
Received on 2001-11-08