cURL / Mailing Lists / curl-library / Single Mail


Re: Query in curl library behavior when curl_easy_perform fails

From: Daniel Stenberg <>
Date: Fri, 10 Jun 2016 16:11:24 +0200 (CEST)

On Fri, 10 Jun 2016, Ramachandran, Agalya (Contractor) wrote:

> w_curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_func);
> w_curl_easy_setopt(handle, CURLOPT_WRITEDATA, &res_body);
> When curl_easy_perform API call is success, I could able to retrieve the
> result body from the res_body. But in the case of API call failure am not
> getting any details of the message. But getting only the http response code.
> Is there a way to get the message details as well in the case where
> curl_easy_perform API fails?

The argument you set with CURLOPT_WRITEDATA is never touched by libcurl. It is
passed on as an argument to the callback you set with CURLOPT_WRITEFUNCTION.

Your callback then probably uses the CURLOPT_WRITEDATA pointer.

When curl_easy_perform() then ultimately returns, libcurl still doesn't touch
the pointer passed in with CURLOPT_WRITEDATA. If your callback stored data
there, then it remains there no matter if libcurl returned success or failure.
It doesn't even know if your callback did that or not. It is beyond what
libcurl knows or cares about.

> LM_INFO(" Actual result body is %s\n", res_body.s);
> When I print this, in the case of success, am getting a http response message in detail.
> But in case of failure it only returns error code.

Maybe you just don't get any body (sent to the callback) from the server in
the case of failure?

List admin:
Received on 2016-06-10