Reputation: 51
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
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