1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_FAILONERROR 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_RESPONSE_CODE (3) 9 - CURLOPT_HTTP200ALIASES (3) 10 - CURLOPT_KEEP_SENDING_ON_ERROR (3) 11Protocol: 12 - HTTP 13Added-in: 7.1 14--- 15 16# NAME 17 18CURLOPT_FAILONERROR - request failure on HTTP response \>= 400 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FAILONERROR, long fail); 26~~~ 27 28# DESCRIPTION 29 30A long parameter set to 1 tells the library to fail the request if the HTTP 31code returned is equal to or larger than 400. The default action would be to 32return the page normally, ignoring that code. 33 34This method is not fail-safe and there are occasions where non-successful 35response codes slip through, especially when authentication is involved 36(response codes 401 and 407). 37 38You might get some amounts of headers transferred before this situation is 39detected, like when a "100-continue" is received as a response to a POST/PUT 40and a 401 or 407 is received immediately afterwards. 41 42When this option is used and an error is detected, it causes the connection to 43get closed and *CURLE_HTTP_RETURNED_ERROR* is returned. 44 45# DEFAULT 46 470, do not fail on error 48 49# %PROTOCOLS% 50 51# EXAMPLE 52 53~~~c 54int main(void) 55{ 56 CURL *curl = curl_easy_init(); 57 if(curl) { 58 CURLcode ret; 59 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 60 curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); 61 ret = curl_easy_perform(curl); 62 if(ret == CURLE_HTTP_RETURNED_ERROR) { 63 /* an HTTP response error problem */ 64 } 65 } 66} 67~~~ 68 69# %AVAILABILITY% 70 71# RETURN VALUE 72 73Returns CURLE_OK if HTTP is enabled, and CURLE_UNKNOWN_OPTION if not. 74