xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_COPYPOSTFIELDS.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
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_COPYPOSTFIELDS
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_MIMEPOST (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_POSTFIELDS (3)
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_POSTFIELDSIZE (3)
11*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_UPLOAD (3)
12*6236dae4SAndroid Build Coastguard WorkerProtocol:
13*6236dae4SAndroid Build Coastguard Worker  - HTTP
14*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.17.1
15*6236dae4SAndroid Build Coastguard Worker---
16*6236dae4SAndroid Build Coastguard Worker
17*6236dae4SAndroid Build Coastguard Worker# NAME
18*6236dae4SAndroid Build Coastguard Worker
19*6236dae4SAndroid Build Coastguard WorkerCURLOPT_COPYPOSTFIELDS - have libcurl copy data to POST
20*6236dae4SAndroid Build Coastguard Worker
21*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
22*6236dae4SAndroid Build Coastguard Worker
23*6236dae4SAndroid Build Coastguard Worker~~~c
24*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
25*6236dae4SAndroid Build Coastguard Worker
26*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_COPYPOSTFIELDS, char *data);
27*6236dae4SAndroid Build Coastguard Worker~~~
28*6236dae4SAndroid Build Coastguard Worker
29*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
30*6236dae4SAndroid Build Coastguard Worker
31*6236dae4SAndroid Build Coastguard WorkerPass a char pointer as parameter, which should be the full *data* to post in a
32*6236dae4SAndroid Build Coastguard WorkerHTTP POST operation. It behaves as the CURLOPT_POSTFIELDS(3) option, but the
33*6236dae4SAndroid Build Coastguard Workeroriginal data is instead copied by the library, allowing the application to
34*6236dae4SAndroid Build Coastguard Workeroverwrite the original data after setting this option.
35*6236dae4SAndroid Build Coastguard Worker
36*6236dae4SAndroid Build Coastguard WorkerBecause data is copied, care must be taken when using this option in
37*6236dae4SAndroid Build Coastguard Workerconjunction with CURLOPT_POSTFIELDSIZE(3) or CURLOPT_POSTFIELDSIZE_LARGE(3).
38*6236dae4SAndroid Build Coastguard WorkerIf the size has not been set prior to CURLOPT_COPYPOSTFIELDS(3), the data is
39*6236dae4SAndroid Build Coastguard Workerassumed to be a null-terminated string; else the stored size informs the
40*6236dae4SAndroid Build Coastguard Workerlibrary about the byte count to copy. In any case, the size must not be
41*6236dae4SAndroid Build Coastguard Workerchanged after CURLOPT_COPYPOSTFIELDS(3), unless another CURLOPT_POSTFIELDS(3)
42*6236dae4SAndroid Build Coastguard Workeror CURLOPT_COPYPOSTFIELDS(3) option is set.
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. Set it to NULL to disable its use again.
49*6236dae4SAndroid Build Coastguard Worker
50*6236dae4SAndroid Build Coastguard Worker# DEFAULT
51*6236dae4SAndroid Build Coastguard Worker
52*6236dae4SAndroid Build Coastguard WorkerNULL
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
55*6236dae4SAndroid Build Coastguard Worker
56*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
57*6236dae4SAndroid Build Coastguard Worker
58*6236dae4SAndroid Build Coastguard Worker~~~c
59*6236dae4SAndroid Build Coastguard Workerint main(void)
60*6236dae4SAndroid Build Coastguard Worker{
61*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
62*6236dae4SAndroid Build Coastguard Worker  if(curl) {
63*6236dae4SAndroid Build Coastguard Worker    char local_buffer[1024]="data to send";
64*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
65*6236dae4SAndroid Build Coastguard Worker
66*6236dae4SAndroid Build Coastguard Worker    /* size of the data to copy from the buffer and send in the request */
67*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
68*6236dae4SAndroid Build Coastguard Worker
69*6236dae4SAndroid Build Coastguard Worker    /* send data from the local stack */
70*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer);
71*6236dae4SAndroid Build Coastguard Worker
72*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
73*6236dae4SAndroid Build Coastguard Worker  }
74*6236dae4SAndroid Build Coastguard Worker}
75*6236dae4SAndroid Build Coastguard Worker~~~
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
78*6236dae4SAndroid Build Coastguard Worker
79*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
80*6236dae4SAndroid Build Coastguard Worker
81*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
82*6236dae4SAndroid Build Coastguard WorkerCURLE_OUT_OF_MEMORY if there was insufficient heap space.
83