1CURLOPT_CUSTOMREQUEST(3) curl_easy_setopt options CURLOPT_CUSTOMREQUEST(3)
2
3
4
6 CURLOPT_CUSTOMREQUEST - custom string for request
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CUSTOMREQUEST, char
12 *request);
13
15 Pass a pointer to a null-terminated string as parameter.
16
17 When you change the request method by setting CURLOPT_CUSTOMREQUEST(3)
18 to something, you don't actually change how libcurl behaves or acts in
19 regards to the particular request method, it will only change the ac‐
20 tual string sent in the request.
21
22 Restore to the internal default by setting this to NULL.
23
24 This option can be used to specify the request:
25
26 HTTP Instead of GET or HEAD when performing HTTP based requests. This
27 is particularly useful, for example, for performing an HTTP
28 DELETE request.
29
30 For example:
31
32 When you tell libcurl to do a HEAD request, but then specify a
33 GET though a custom request libcurl will still act as if it sent
34 a HEAD. To switch to a proper HEAD use CURLOPT_NOBODY(3), to
35 switch to a proper POST use CURLOPT_POST(3) or CURLOPT_POST‐
36 FIELDS(3) and to switch to a proper GET use CURLOPT_HTTPGET(3).
37
38 Many people have wrongly used this option to replace the entire
39 request with their own, including multiple headers and POST con‐
40 tents. While that might work in many cases, it will cause
41 libcurl to send invalid requests and it could possibly confuse
42 the remote server badly. Use CURLOPT_POST(3) and CURLOPT_POST‐
43 FIELDS(3) to set POST data. Use CURLOPT_HTTPHEADER(3) to replace
44 or extend the set of headers sent by libcurl. Use CUR‐
45 LOPT_HTTP_VERSION(3) to change HTTP version.
46
47
48 FTP Instead of LIST and NLST when performing FTP directory listings.
49
50 IMAP Instead of LIST when issuing IMAP based requests.
51
52 POP3 Instead of LIST and RETR when issuing POP3 based requests.
53
54 For example:
55
56 When you tell libcurl to use a custom request it will behave
57 like a LIST or RETR command was sent where it expects data to be
58 returned by the server. As such CURLOPT_NOBODY(3) should be used
59 when specifying commands such as DELE and NOOP for example.
60
61 SMTP Instead of a HELP or VRFY when issuing SMTP based requests.
62
63 For example:
64
65 Normally a multiline response is returned which can be used, in
66 conjunction with CURLOPT_MAIL_RCPT(3), to specify an EXPN re‐
67 quest. If the CURLOPT_NOBODY(3) option is specified then the re‐
68 quest can be used to issue NOOP and RSET commands.
69
70 The application does not have to keep the string around after
71 setting this option.
72
74 NULL
75
77 HTTP, FTP, IMAP, POP3 and SMTP
78
80 CURL *curl = curl_easy_init();
81 if(curl) {
82 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
83
84 /* DELETE the given path */
85 curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
86
87 ret = curl_easy_perform(curl);
88
89 curl_easy_cleanup(curl);
90 }
91
93 IMAP is supported since 7.30.0, POP3 since 7.26.0 and SMTP since
94 7.34.0.
95
97 Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if
98 not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space.
99
101 CURLOPT_HTTPHEADER(3), CURLOPT_NOBODY(3), CURLOPT_REQUEST_TARGET(3),
102
103
104
105libcurl 7.76.1 November 04, 2020 CURLOPT_CUSTOMREQUEST(3)