1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_CUSTOMREQUEST 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLINFO_EFFECTIVE_METHOD (3) 9*6236dae4SAndroid Build Coastguard Worker - CURLOPT_HTTPHEADER (3) 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_NOBODY (3) 11*6236dae4SAndroid Build Coastguard Worker - CURLOPT_REQUEST_TARGET (3) 12*6236dae4SAndroid Build Coastguard WorkerProtocol: 13*6236dae4SAndroid Build Coastguard Worker - HTTP 14*6236dae4SAndroid Build Coastguard Worker - FTP 15*6236dae4SAndroid Build Coastguard Worker - IMAP 16*6236dae4SAndroid Build Coastguard Worker - POP3 17*6236dae4SAndroid Build Coastguard Worker - SMTP 18*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1 19*6236dae4SAndroid Build Coastguard Worker--- 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker# NAME 22*6236dae4SAndroid Build Coastguard Worker 23*6236dae4SAndroid Build Coastguard WorkerCURLOPT_CUSTOMREQUEST - custom request method 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard Worker~~~c 28*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 29*6236dae4SAndroid Build Coastguard Worker 30*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_CUSTOMREQUEST, char *method); 31*6236dae4SAndroid Build Coastguard Worker~~~ 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 34*6236dae4SAndroid Build Coastguard Worker 35*6236dae4SAndroid Build Coastguard WorkerPass a pointer to a null-terminated string as parameter. 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard WorkerWhen changing the request *method* by setting CURLOPT_CUSTOMREQUEST(3), you do 38*6236dae4SAndroid Build Coastguard Workernot actually change how libcurl behaves or acts: you only change the actual 39*6236dae4SAndroid Build Coastguard Workerstring sent in the request. 40*6236dae4SAndroid Build Coastguard Worker 41*6236dae4SAndroid Build Coastguard Workerlibcurl passes on the verbatim string in its request without any filter or 42*6236dae4SAndroid Build Coastguard Workerother safe guards. That includes white space and control characters. 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this 45*6236dae4SAndroid Build Coastguard Workeroption. 46*6236dae4SAndroid Build Coastguard Worker 47*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set string override the 48*6236dae4SAndroid Build Coastguard Workerprevious ones. Restore to the internal default by setting this to NULL. 49*6236dae4SAndroid Build Coastguard Worker 50*6236dae4SAndroid Build Coastguard WorkerThis option can be used to specify the request: 51*6236dae4SAndroid Build Coastguard Worker 52*6236dae4SAndroid Build Coastguard Worker## HTTP 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerInstead of GET or HEAD when performing HTTP based requests. This is 55*6236dae4SAndroid Build Coastguard Workerparticularly useful, for example, for performing an HTTP DELETE request. 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard WorkerFor example: 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard WorkerWhen you tell libcurl to do a HEAD request, but then specify a GET though a 60*6236dae4SAndroid Build Coastguard Workercustom request libcurl still acts as if it sent a HEAD. To switch to a proper 61*6236dae4SAndroid Build Coastguard WorkerHEAD use CURLOPT_NOBODY(3), to switch to a proper POST use 62*6236dae4SAndroid Build Coastguard WorkerCURLOPT_POST(3) or CURLOPT_POSTFIELDS(3) and to switch to a proper 63*6236dae4SAndroid Build Coastguard WorkerGET use CURLOPT_HTTPGET(3). 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard WorkerMany people have wrongly used this option to replace the entire request with 66*6236dae4SAndroid Build Coastguard Workertheir own, including multiple headers and POST contents. While that might work 67*6236dae4SAndroid Build Coastguard Workerin many cases, it might cause libcurl to send invalid requests and it could 68*6236dae4SAndroid Build Coastguard Workerpossibly confuse the remote server badly. Use CURLOPT_POST(3) and 69*6236dae4SAndroid Build Coastguard WorkerCURLOPT_POSTFIELDS(3) to set POST data. Use CURLOPT_HTTPHEADER(3) 70*6236dae4SAndroid Build Coastguard Workerto replace or extend the set of headers sent by libcurl. Use 71*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HTTP_VERSION(3) to change HTTP version. 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard Worker## FTP 74*6236dae4SAndroid Build Coastguard Worker 75*6236dae4SAndroid Build Coastguard WorkerInstead of LIST and NLST when performing FTP directory listings. 76*6236dae4SAndroid Build Coastguard Worker 77*6236dae4SAndroid Build Coastguard Worker## IMAP 78*6236dae4SAndroid Build Coastguard Worker 79*6236dae4SAndroid Build Coastguard WorkerInstead of LIST when issuing IMAP based requests. 80*6236dae4SAndroid Build Coastguard Worker 81*6236dae4SAndroid Build Coastguard Worker## POP3 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard WorkerInstead of LIST and RETR when issuing POP3 based requests. 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard WorkerFor example: 86*6236dae4SAndroid Build Coastguard Worker 87*6236dae4SAndroid Build Coastguard WorkerWhen you tell libcurl to use a custom request it behaves like a LIST or RETR 88*6236dae4SAndroid Build Coastguard Workercommand was sent where it expects data to be returned by the server. As such 89*6236dae4SAndroid Build Coastguard WorkerCURLOPT_NOBODY(3) should be used when specifying commands such as 90*6236dae4SAndroid Build Coastguard Worker**DELE** and **NOOP** for example. 91*6236dae4SAndroid Build Coastguard Worker 92*6236dae4SAndroid Build Coastguard Worker## SMTP 93*6236dae4SAndroid Build Coastguard Worker 94*6236dae4SAndroid Build Coastguard WorkerInstead of a **HELP** or **VRFY** when issuing SMTP based requests. 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard WorkerFor example: 97*6236dae4SAndroid Build Coastguard Worker 98*6236dae4SAndroid Build Coastguard WorkerNormally a multi line response is returned which can be used, in conjunction 99*6236dae4SAndroid Build Coastguard Workerwith CURLOPT_MAIL_RCPT(3), to specify an EXPN request. If the 100*6236dae4SAndroid Build Coastguard WorkerCURLOPT_NOBODY(3) option is specified then the request can be used to 101*6236dae4SAndroid Build Coastguard Workerissue **NOOP** and **RSET** commands. 102*6236dae4SAndroid Build Coastguard Worker 103*6236dae4SAndroid Build Coastguard Worker# DEFAULT 104*6236dae4SAndroid Build Coastguard Worker 105*6236dae4SAndroid Build Coastguard WorkerNULL 106*6236dae4SAndroid Build Coastguard Worker 107*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 108*6236dae4SAndroid Build Coastguard Worker 109*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 110*6236dae4SAndroid Build Coastguard Worker 111*6236dae4SAndroid Build Coastguard Worker~~~c 112*6236dae4SAndroid Build Coastguard Workerint main(void) 113*6236dae4SAndroid Build Coastguard Worker{ 114*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 115*6236dae4SAndroid Build Coastguard Worker if(curl) { 116*6236dae4SAndroid Build Coastguard Worker CURLcode res; 117*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 118*6236dae4SAndroid Build Coastguard Worker 119*6236dae4SAndroid Build Coastguard Worker /* DELETE the given path */ 120*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE"); 121*6236dae4SAndroid Build Coastguard Worker 122*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl); 123*6236dae4SAndroid Build Coastguard Worker 124*6236dae4SAndroid Build Coastguard Worker curl_easy_cleanup(curl); 125*6236dae4SAndroid Build Coastguard Worker } 126*6236dae4SAndroid Build Coastguard Worker} 127*6236dae4SAndroid Build Coastguard Worker~~~ 128*6236dae4SAndroid Build Coastguard Worker 129*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 130*6236dae4SAndroid Build Coastguard Worker 131*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 132*6236dae4SAndroid Build Coastguard Worker 133*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or 134*6236dae4SAndroid Build Coastguard WorkerCURLE_OUT_OF_MEMORY if there was insufficient heap space. 135