• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_RESPONSE_CODE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_HTTP_CONNECTCODE (3)
9  - curl_easy_getinfo (3)
10  - curl_easy_setopt (3)
11---
12
13# NAME
14
15CURLINFO_RESPONSE_CODE - get the last response code
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_RESPONSE_CODE, long *codep);
23~~~
24
25# DESCRIPTION
26
27Pass a pointer to a long to receive the last received HTTP, FTP, SMTP or LDAP
28(OpenLDAP only) response code. This option was previously known as
29CURLINFO_HTTP_CODE in libcurl 7.10.7 and earlier. The stored value is zero if
30no server response code has been received.
31
32Note that a proxy's CONNECT response should be read with
33CURLINFO_HTTP_CONNECTCODE(3) and not this.
34
35# PROTOCOLS
36
37HTTP, FTP, SMTP and LDAP
38
39# EXAMPLE
40
41~~~c
42int main(void)
43{
44  CURL *curl = curl_easy_init();
45  if(curl) {
46    CURLcode res;
47    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
48    res = curl_easy_perform(curl);
49    if(res == CURLE_OK) {
50      long response_code;
51      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
52    }
53    curl_easy_cleanup(curl);
54  }
55}
56~~~
57
58# AVAILABILITY
59
60Added in 7.10.8. CURLINFO_HTTP_CODE was added in 7.4.1.
61Support for SMTP responses added in 7.25.0, for OpenLDAP in 7.81.0.
62
63# RETURN VALUE
64
65Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
66