CURLOPT_FAILONERROR.md (1822B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_FAILONERROR 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_RESPONSE_CODE (3) 9 - CURLOPT_HTTP200ALIASES (3) 10 - CURLOPT_KEEP_SENDING_ON_ERROR (3) 11 Protocol: 12 - HTTP 13 Added-in: 7.1 14 --- 15 16 # NAME 17 18 CURLOPT_FAILONERROR - request failure on HTTP response \>= 400 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FAILONERROR, long fail); 26 ~~~ 27 28 # DESCRIPTION 29 30 A long parameter set to 1 tells the library to fail the request if the HTTP 31 code returned is equal to or larger than 400. The default action would be to 32 return the page normally, ignoring that code. 33 34 This method is not fail-safe and there are occasions where non-successful 35 response codes slip through, especially when authentication is involved 36 (response codes 401 and 407). 37 38 You might get some amounts of headers transferred before this situation is 39 detected, like when a "100-continue" is received as a response to a POST/PUT 40 and a 401 or 407 is received immediately afterwards. 41 42 When this option is used and an error is detected, it causes the connection to 43 get closed and *CURLE_HTTP_RETURNED_ERROR* is returned. 44 45 # DEFAULT 46 47 0, do not fail on error 48 49 # %PROTOCOLS% 50 51 # EXAMPLE 52 53 ~~~c 54 int 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 73 curl_easy_setopt(3) returns a CURLcode indicating success or error. 74 75 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 76 libcurl-errors(3).