Commit c857bb68 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

opts: added examples

parent 005f2ada
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@ CURLOPT_COPYPOSTFIELDS \- have libcurl copy data to POST

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COPYPOSTFIELDS, char *data);
.SH DESCRIPTION
Pass a char * as parameter, which should be the full data to post in a HTTP
POST operation. It behaves as the \fICURLOPT_POSTFIELDS(3)\fP option, but the
original data is instead copied by the library, allowing the application to
overwrite the original data after setting this option.
Pass a char * as parameter, which should be the full \fIdata\fP to post in a
HTTP POST operation. It behaves as the \fICURLOPT_POSTFIELDS(3)\fP option, but
the original data is instead copied by the library, allowing the application
to overwrite the original data after setting this option.

Because data are copied, care must be taken when using this option in
conjunction with \fICURLOPT_POSTFIELDSIZE(3)\fP or
@@ -44,9 +44,23 @@ copy. In any case, the size must not be changed after
.SH DEFAULT
NULL
.SH PROTOCOLS
HTTP
HTTP(S)
.SH EXAMPLE
TODO
.nf
CURL *curl = curl_easy_init();
if(curl) {
  char local_buffer[1024]="data to send";
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");

  /* size of the data to copy from the buffer and send in the request */
  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);

  /* send data from the local stack */
  curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, local_buffer);

  curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY
Added in 7.17.1
.SH RETURN VALUE
+19 −2
Original line number Diff line number Diff line
@@ -39,15 +39,32 @@ redirects libcurl will follow.
libcurl can limit to what protocols it will automatically follow. The accepted
protocols are set with \fICURLOPT_REDIR_PROTOCOLS(3)\fP and it excludes the
FILE protocol by default.

For users who think the existing location following is too naive, too simple
or just lacks features, it is very easy to instead implement your own redirect
follow logic with the use of \fIcurl_easy_getinfo(3)\fP's
\fICURLINFO_REDIRECT_URL\fP option instead of using
\fICURLOPT_FOLLOWLOCATION(3)\fP.
.SH DEFAULT
0, disabled
.SH PROTOCOLS
HTTP
HTTP(S)
.SH EXAMPLE
TODO
.nf
CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");

  /* example.com is redirected, so we tell libcurl to follow redirection */
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

  curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY
Along with HTTP
.SH RETURN VALUE
Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
.SH "SEE ALSO"
.BR CURLOPT_REDIR_PROTOCOLS "(3), " CURLOPT_PROTOCOLS "(3), "
.BR CURLOPT_POSTREDIR "(3), "
+13 −2
Original line number Diff line number Diff line
@@ -37,9 +37,20 @@ When setting \fICURLOPT_HTTPGET(3)\fP to 1, it will automatically set
.SH DEFAULT
0
.SH PROTOCOLS
HTTP
HTTP(S)
.SH EXAMPLE
TODO
.nf
curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");

  /* use a GET to fetch this */ 
  curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);

  /* Perform the request */ 
  curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY
Along with HTTP
.SH RETURN VALUE
+23 −1
Original line number Diff line number Diff line
@@ -47,7 +47,29 @@ NULL
.SH PROTOCOLS
HTTP
.SH EXAMPLE
TODO
.nf
/* Fill in the file upload field. This makes libcurl load data from
   the given file name when curl_easy_perform() is called. */
curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "sendfile",
             CURLFORM_FILE, "postit2.c",
             CURLFORM_END);

/* Fill in the filename field */
curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "filename",
             CURLFORM_COPYCONTENTS, "postit2.c",
             CURLFORM_END);

/* Fill in the submit field too, even if this is rarely needed */
curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "submit",
             CURLFORM_COPYCONTENTS, "send",
             CURLFORM_END);
.fi
.SH AVAILABILITY
As long as HTTP is enabled
.SH RETURN VALUE
+16 −2
Original line number Diff line number Diff line
@@ -39,9 +39,23 @@ Set it to -1 for an infinite number of redirects.
.SH DEFAULT
-1, unlimited
.SH PROTOCOLS
HTTP
HTTP(S)
.SH EXAMPLE
TODO
.nf
curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");

  /* enable redirect following */
  curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

  /* allow three redirects */
  curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L);

  /* Perform the request */
  curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY
Along with HTTP
.SH RETURN VALUE
Loading