RSH
RSH

Reputation: 51

LibCurl how to catch both 400, not as a part of CURLE_HTTP_RETURNED_ERROR error

In C++ Libcurl library, distinguish http error 400 from 404? I have following code. I'm catching >=400 using CURLE_HTTP_RETURNED_ERROR but I want to catch error 400 separately before CURLE_HTTP_RETURNED_ERROR case. Is there a way to do that?

curlCode = curl_easy_perform(request);
.....
switch(curlCode)
{
   case CURLE_HTTP_RETURNED_ERROR:

}

Upvotes: 1

Views: 1692

Answers (1)

Barmar
Barmar

Reputation: 781350

curl_easy_getinfo allows you to get the response code.

long responseCode;
curlCode = curl_easy_perform(request);
curl_easy_getinfo(request, CURLINFO_RESPONSE_CODE, &responseCode);
if (responseCode == 400) {
    // handle error 400
} else {
    switch (curlCode) {
        ...
    }
}

Upvotes: 6

Related Questions