The api I’m calling returns a json object of validation errors with the HTTP code 400. I implemented the client using PHP’s curl library, but on error curl_exec returns false. How can I get the response body on error?
Note that I am setting curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
You can unset
CURLOPT_FAILONERRORfor once. And adding your error status code toCURLOPT_HTTP200ALIASESas expected might also help.(libcurl also has a
CURLOPT_ERRORBUFFER, but you cannot use that option from PHP.)Btw, curl behaves correctly by not returning the response body in case of 4xx errors. Not sure if that can be overriden. So you might have to migrate to
PEAR HTTP_Request2or a similar HTTP request class where you can deviate from the standard.