cURL / Mailing Lists / curl-users / Single Mail

curl-users

curl_easy_perform blocks when trying to read a response Header

From: Ambarish Mitra <ambarish_mitra_at_persistent.co.in>
Date: Thu, 6 Nov 2008 19:16:26 +0530

I am trying to get the HTTP response from a simple servlet. The trouble is:
the program blocks 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
{
                System.out.println("doget - start ");
                ....
                response.setStatus(200);
                System.out.println("doget - end ");
}
       

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:

char *hdrdata;

size_t WriteHeaderCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
        size_t realsize = size * nmemb;
        hdrdata = (char *) malloc (realsize);
        memcpy(hdrdata, ptr, realsize);
        return realsize;
}

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

/* The program blocks at this perform function. The servlet starts and
completes but this does not go ahead.
    Other HTTP client completes, so there is 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.

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

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.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html

Received on 2008-11-06