CURLOPT_CUSTOMREQUEST.3 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. .\" generated by cd2nroff 0.1 from CURLOPT_CUSTOMREQUEST.md
  2. .TH CURLOPT_CUSTOMREQUEST 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_CUSTOMREQUEST \- custom request method
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CUSTOMREQUEST, char *method);
  9. .fi
  10. .SH DESCRIPTION
  11. Pass a pointer to a null\-terminated string as parameter.
  12. When changing the request \fImethod\fP by setting \fICURLOPT_CUSTOMREQUEST(3)\fP, you
  13. do not actually change how libcurl behaves or acts: you only change the actual
  14. string sent in the request.
  15. libcurl passes on the verbatim string in its request without any filter or
  16. other safe guards. That includes white space and control characters.
  17. Restore to the internal default by setting this to NULL.
  18. This option can be used to specify the request:
  19. .IP HTTP
  20. Instead of GET or HEAD when performing HTTP based requests. This is
  21. particularly useful, for example, for performing an HTTP DELETE request.
  22. For example:
  23. When you tell libcurl to do a HEAD request, but then specify a GET though a
  24. custom request libcurl still acts as if it sent a HEAD. To switch to a proper
  25. HEAD use \fICURLOPT_NOBODY(3)\fP, to switch to a proper POST use
  26. \fICURLOPT_POST(3)\fP or \fICURLOPT_POSTFIELDS(3)\fP and to switch to a proper
  27. GET use \fICURLOPT_HTTPGET(3)\fP.
  28. Many people have wrongly used this option to replace the entire request with
  29. their own, including multiple headers and POST contents. While that might work
  30. in many cases, it might cause libcurl to send invalid requests and it could
  31. possibly confuse the remote server badly. Use \fICURLOPT_POST(3)\fP and
  32. \fICURLOPT_POSTFIELDS(3)\fP to set POST data. Use \fICURLOPT_HTTPHEADER(3)\fP
  33. to replace or extend the set of headers sent by libcurl. Use
  34. \fICURLOPT_HTTP_VERSION(3)\fP to change HTTP version.
  35. .IP FTP
  36. Instead of LIST and NLST when performing FTP directory listings.
  37. .IP IMAP
  38. Instead of LIST when issuing IMAP based requests.
  39. .IP POP3
  40. Instead of LIST and RETR when issuing POP3 based requests.
  41. For example:
  42. When you tell libcurl to use a custom request it behaves like a LIST or RETR
  43. command was sent where it expects data to be returned by the server. As such
  44. \fICURLOPT_NOBODY(3)\fP should be used when specifying commands such as
  45. \fBDELE\fP and \fBNOOP\fP for example.
  46. .IP SMTP
  47. Instead of a \fBHELP\fP or \fBVRFY\fP when issuing SMTP based requests.
  48. For example:
  49. Normally a multi line response is returned which can be used, in conjunction
  50. with \fICURLOPT_MAIL_RCPT(3)\fP, to specify an EXPN request. If the
  51. \fICURLOPT_NOBODY(3)\fP option is specified then the request can be used to
  52. issue \fBNOOP\fP and \fBRSET\fP commands.
  53. .SH DEFAULT
  54. NULL
  55. .SH PROTOCOLS
  56. This functionality affects ftp, http, imap, pop3 and smtp
  57. .SH EXAMPLE
  58. .nf
  59. int main(void)
  60. {
  61. CURL *curl = curl_easy_init();
  62. if(curl) {
  63. CURLcode res;
  64. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
  65. /* DELETE the given path */
  66. curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
  67. res = curl_easy_perform(curl);
  68. curl_easy_cleanup(curl);
  69. }
  70. }
  71. .fi
  72. .SH AVAILABILITY
  73. Added in curl 7.1
  74. .SH RETURN VALUE
  75. Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
  76. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  77. .SH SEE ALSO
  78. .BR CURLINFO_EFFECTIVE_METHOD (3),
  79. .BR CURLOPT_HTTPHEADER (3),
  80. .BR CURLOPT_NOBODY (3),
  81. .BR CURLOPT_REQUEST_TARGET (3)