cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl_easy_perform hangs when trying to read response headers

From: Ambarish Mitra <ambarish_mitra_at_persistent.co.in>
Date: Mon, 10 Nov 2008 16:13:38 +0530

Hi,

I am trying to get the HTTP response from a simple servlet, but the program
hangs at curl_easy_perform, and does not come out of it even if the servlet
has completed.

I have a running test Java servlet (deployed on Tomcat), which returns a
response code of 200.

protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
                ....
        response.setStatus(200);
}

I am attempting to write a C program using libcurl, which will just get the
response header. I have implemented the callback using
CURLOPT_HEADERFUNCTION. Code snippet below. Obviously, there is some mistake
out here. I tried with some other HTTP clients (wfetch), and there the
program completes, and it gets the response code 200.

Code snippet:

struct MemoryStruct
{
        char* memory;
        size_t size;
};

struct MemoryStruct resHeaders;

size_t WriteHeaderCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
        // Getting the response headers here.
}

...
curl_easy_setopt(hCurl, CURLOPT_HEADERFUNCTION, WriteHeaderCallback);
curl_easy_setopt(hCurl, CURLOPT_WRITEHEADER, (void *)&resHeaders);
...

/* The program hangs at this perform function. The servlet starts and
completes but this does not go ahead.
    Other HTTP client completes, so there seems to be no issue with the
servlet.
*/

if (curl_easy_perform(hCurl) == CURLE_OK)
                printf("Perform Ok\n");
        else
        {
                printf("\tError from cURL: %s\n", curl_easy_strerror(res));
                return -1;
        }

Any guidance would be nice. Where did I make a mistake?

-bash-3.00$ curl --version
curl 7.19.0 (sparc-sun-solaris2.10) libcurl/7.19.0 OpenSSL/0.9.8h zlib/1.2.3
Protocols: dict http file https
Features: Debug IPv6 Largefile NTLM SSL libz

Thanks in advance.

// Pls ignore the disclaimer.

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
Received on 2008-11-10