CURLOPT_FAILONERROR.3 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. .\" generated by cd2nroff 0.1 from CURLOPT_FAILONERROR.md
  2. .TH CURLOPT_FAILONERROR 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_FAILONERROR \- request failure on HTTP response >= 400
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FAILONERROR, long fail);
  9. .fi
  10. .SH DESCRIPTION
  11. A long parameter set to 1 tells the library to fail the request if the HTTP
  12. code returned is equal to or larger than 400. The default action would be to
  13. return the page normally, ignoring that code.
  14. This method is not fail\-safe and there are occasions where non\-successful
  15. response codes slip through, especially when authentication is involved
  16. (response codes 401 and 407).
  17. You might get some amounts of headers transferred before this situation is
  18. detected, like when a "100\-continue" is received as a response to a POST/PUT
  19. and a 401 or 407 is received immediately afterwards.
  20. When this option is used and an error is detected, it causes the connection to
  21. get closed and \fICURLE_HTTP_RETURNED_ERROR\fP is returned.
  22. .SH DEFAULT
  23. 0, do not fail on error
  24. .SH PROTOCOLS
  25. This functionality affects http only
  26. .SH EXAMPLE
  27. .nf
  28. int main(void)
  29. {
  30. CURL *curl = curl_easy_init();
  31. if(curl) {
  32. CURLcode ret;
  33. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  34. curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
  35. ret = curl_easy_perform(curl);
  36. if(ret == CURLE_HTTP_RETURNED_ERROR) {
  37. /* an HTTP response error problem */
  38. }
  39. }
  40. }
  41. .fi
  42. .SH AVAILABILITY
  43. Added in curl 7.1
  44. .SH RETURN VALUE
  45. Returns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not.
  46. .SH SEE ALSO
  47. .BR CURLINFO_RESPONSE_CODE (3),
  48. .BR CURLOPT_HTTP200ALIASES (3),
  49. .BR CURLOPT_KEEP_SENDING_ON_ERROR (3)