1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_CUSTOMREQUEST
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_EFFECTIVE_METHOD (3)
9  - CURLOPT_HTTPHEADER (3)
10  - CURLOPT_NOBODY (3)
11  - CURLOPT_REQUEST_TARGET (3)
12---
13
14# NAME
15
16CURLOPT_CUSTOMREQUEST - custom request method
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CUSTOMREQUEST, char *method);
24~~~
25
26# DESCRIPTION
27
28Pass a pointer to a null-terminated string as parameter.
29
30When changing the request *method* by setting CURLOPT_CUSTOMREQUEST(3), you
31do not actually change how libcurl behaves or acts: you only change the actual
32string sent in the request.
33
34libcurl passes on the verbatim string in its request without any filter or
35other safe guards. That includes white space and control characters.
36
37Restore to the internal default by setting this to NULL.
38
39This option can be used to specify the request:
40
41## HTTP
42
43Instead of GET or HEAD when performing HTTP based requests. This is
44particularly useful, for example, for performing an HTTP DELETE request.
45
46For example:
47
48When you tell libcurl to do a HEAD request, but then specify a GET though a
49custom request libcurl still acts as if it sent a HEAD. To switch to a proper
50HEAD use CURLOPT_NOBODY(3), to switch to a proper POST use
51CURLOPT_POST(3) or CURLOPT_POSTFIELDS(3) and to switch to a proper
52GET use CURLOPT_HTTPGET(3).
53
54Many people have wrongly used this option to replace the entire request with
55their own, including multiple headers and POST contents. While that might work
56in many cases, it might cause libcurl to send invalid requests and it could
57possibly confuse the remote server badly. Use CURLOPT_POST(3) and
58CURLOPT_POSTFIELDS(3) to set POST data. Use CURLOPT_HTTPHEADER(3)
59to replace or extend the set of headers sent by libcurl. Use
60CURLOPT_HTTP_VERSION(3) to change HTTP version.
61
62## FTP
63
64Instead of LIST and NLST when performing FTP directory listings.
65
66## IMAP
67
68Instead of LIST when issuing IMAP based requests.
69
70## POP3
71
72Instead of LIST and RETR when issuing POP3 based requests.
73
74For example:
75
76When you tell libcurl to use a custom request it behaves like a LIST or RETR
77command was sent where it expects data to be returned by the server. As such
78CURLOPT_NOBODY(3) should be used when specifying commands such as
79**DELE** and **NOOP** for example.
80
81## SMTP
82
83Instead of a **HELP** or **VRFY** when issuing SMTP based requests.
84
85For example:
86
87Normally a multi line response is returned which can be used, in conjunction
88with CURLOPT_MAIL_RCPT(3), to specify an EXPN request. If the
89CURLOPT_NOBODY(3) option is specified then the request can be used to
90issue **NOOP** and **RSET** commands.
91
92The application does not have to keep the string around after setting this
93option.
94
95# DEFAULT
96
97NULL
98
99# PROTOCOLS
100
101HTTP, FTP, IMAP, POP3 and SMTP
102
103# EXAMPLE
104
105~~~c
106int main(void)
107{
108  CURL *curl = curl_easy_init();
109  if(curl) {
110    CURLcode res;
111    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
112
113    /* DELETE the given path */
114    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
115
116    res = curl_easy_perform(curl);
117
118    curl_easy_cleanup(curl);
119  }
120}
121~~~
122
123# AVAILABILITY
124
125IMAP is supported since 7.30.0, POP3 since 7.26.0 and SMTP since 7.34.0.
126
127# RETURN VALUE
128
129Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
130CURLE_OUT_OF_MEMORY if there was insufficient heap space.
131