1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 16:18:48 -05:00

opts: added examples

This commit is contained in:
Daniel Stenberg 2014-10-21 08:58:03 +02:00
parent 005f2adaaa
commit c857bb68ec
14 changed files with 290 additions and 28 deletions

View File

@ -28,10 +28,10 @@ CURLOPT_COPYPOSTFIELDS \- have libcurl copy data to POST
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COPYPOSTFIELDS, char *data); CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COPYPOSTFIELDS, char *data);
.SH DESCRIPTION .SH DESCRIPTION
Pass a char * as parameter, which should be the full data to post in a HTTP Pass a char * as parameter, which should be the full \fIdata\fP to post in a
POST operation. It behaves as the \fICURLOPT_POSTFIELDS(3)\fP option, but the HTTP POST operation. It behaves as the \fICURLOPT_POSTFIELDS(3)\fP option, but
original data is instead copied by the library, allowing the application to the original data is instead copied by the library, allowing the application
overwrite the original data after setting this option. to overwrite the original data after setting this option.
Because data are copied, care must be taken when using this option in Because data are copied, care must be taken when using this option in
conjunction with \fICURLOPT_POSTFIELDSIZE(3)\fP or conjunction with \fICURLOPT_POSTFIELDSIZE(3)\fP or
@ -44,9 +44,23 @@ copy. In any case, the size must not be changed after
.SH DEFAULT .SH DEFAULT
NULL NULL
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP(S)
.SH EXAMPLE .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 .SH AVAILABILITY
Added in 7.17.1 Added in 7.17.1
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -39,15 +39,32 @@ redirects libcurl will follow.
libcurl can limit to what protocols it will automatically follow. The accepted 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 protocols are set with \fICURLOPT_REDIR_PROTOCOLS(3)\fP and it excludes the
FILE protocol by default. 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 .SH DEFAULT
0, disabled 0, disabled
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP(S)
.SH EXAMPLE .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 .SH AVAILABILITY
Along with HTTP Along with HTTP
.SH RETURN VALUE .SH RETURN VALUE
Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
.SH "SEE ALSO" .SH "SEE ALSO"
.BR CURLOPT_REDIR_PROTOCOLS "(3), " CURLOPT_PROTOCOLS "(3), " .BR CURLOPT_REDIR_PROTOCOLS "(3), " CURLOPT_PROTOCOLS "(3), "
.BR CURLOPT_POSTREDIR "(3), "

View File

@ -37,9 +37,20 @@ When setting \fICURLOPT_HTTPGET(3)\fP to 1, it will automatically set
.SH DEFAULT .SH DEFAULT
0 0
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP(S)
.SH EXAMPLE .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 .SH AVAILABILITY
Along with HTTP Along with HTTP
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -47,7 +47,29 @@ NULL
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP
.SH EXAMPLE .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 .SH AVAILABILITY
As long as HTTP is enabled As long as HTTP is enabled
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -39,9 +39,23 @@ Set it to -1 for an infinite number of redirects.
.SH DEFAULT .SH DEFAULT
-1, unlimited -1, unlimited
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP(S)
.SH EXAMPLE .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 .SH AVAILABILITY
Along with HTTP Along with HTTP
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -39,7 +39,18 @@ Enabling this option means asking for a download but without a body.
.SH PROTOCOLS .SH PROTOCOLS
Most Most
.SH EXAMPLE .SH EXAMPLE
TODO .nf
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* get us the resource without a body! */
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
/* Perform the request */
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Always Always
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -58,7 +58,22 @@ NULL
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP
.SH EXAMPLE .SH EXAMPLE
TODO .nf
CURL *curl = curl_easy_init();
if(curl) {
const char *data = "data to send";
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* size of the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 12L);
/* pass in a pointer to the data - libcurl will not copy */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Always Always
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -39,7 +39,21 @@ If you post more than 2GB, use \fICURLOPT_POSTFIELDSIZE_LARGE(3)\fP.
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP
.SH EXAMPLE .SH EXAMPLE
TODO .nf
CURL *curl = curl_easy_init();
if(curl) {
const char *data = "data to send";
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* size of the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data));
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Along with HTTP Along with HTTP
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -37,12 +37,28 @@ set to -1, the library will use strlen() to get the size.
.SH DEFAULT .SH DEFAULT
-1 -1
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP(S)
.SH EXAMPLE .SH EXAMPLE
TODO .nf
CURL *curl = curl_easy_init();
if(curl) {
const char *data = large_chunk;
curl_off_t length_of_data; /* set somehow */
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* size of the POST data */
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, length_of_data);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Along with HTTP Along with HTTP
.SH RETURN VALUE .SH RETURN VALUE
Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
.SH "SEE ALSO" .SH "SEE ALSO"
.BR CURLOPT_POSTFIELDS "(3), " CURLOPT_COPYPOSTFIELDS "(3), " .BR CURLOPT_POSTFIELDS "(3), " CURLOPT_COPYPOSTFIELDS "(3), "
.BR CURLOPT_POSTFIELDSIZE "(3), "

View File

@ -47,9 +47,23 @@ when setting \fICURLOPT_FOLLOWLOCATION(3)\fP.
.SH DEFAULT .SH DEFAULT
0 0
.SH PROTOCOLS .SH PROTOCOLS
HTTP HTTP(S)
.SH EXAMPLE .SH EXAMPLE
TODO .nf
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* a silly POST example */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "data=true");
/* example.com is redirected, so we tell libcurl to send POST on 301, 302 and
303 HTTP response codes */
curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Added in 7.17.1. This option was known as CURLOPT_POST301 up to 7.19.0 as it Added in 7.17.1. This option was known as CURLOPT_POST301 up to 7.19.0 as it
only supported the 301 then. CURL_REDIR_POST_303 was added in 7.26.0. only supported the 301 then. CURL_REDIR_POST_303 was added in 7.26.0.

View File

@ -32,14 +32,57 @@ Pass a long that holds a bitmask of CURLPROTO_* defines. If used, this bitmask
limits what protocols libcurl may use in the transfer. This allows you to have limits what protocols libcurl may use in the transfer. This allows you to have
a libcurl built to support a wide range of protocols but still limit specific a libcurl built to support a wide range of protocols but still limit specific
transfers to only be allowed to use a subset of them. By default libcurl will transfers to only be allowed to use a subset of them. By default libcurl will
accept all protocols it supports. See also accept all protocols it supports (\fICURLPROTO_ALL\fP). See also
\fICURLOPT_REDIR_PROTOCOLS(3)\fP. \fICURLOPT_REDIR_PROTOCOLS(3)\fP.
These are the available protocol defines:
.nf
CURLPROTO_DICT
CURLPROTO_FILE
CURLPROTO_FTP
CURLPROTO_FTPS
CURLPROTO_GOPHER
CURLPROTO_HTTP
CURLPROTO_HTTPS
CURLPROTO_IMAP
CURLPROTO_IMAPS
CURLPROTO_LDAP
CURLPROTO_LDAPS
CURLPROTO_POP3
CURLPROTO_POP3S
CURLPROTO_RTMP
CURLPROTO_RTMPE
CURLPROTO_RTMPS
CURLPROTO_RTMPT
CURLPROTO_RTMPTE
CURLPROTO_RTMPTS
CURLPROTO_RTSP
CURLPROTO_SCP
CURLPROTO_SFTP
CURLPROTO_SMTP
CURLPROTO_SMTPS
CURLPROTO_TELNET
CURLPROTO_TFTP
.fi
.SH DEFAULT .SH DEFAULT
All protocols built-in All protocols built-in
.SH PROTOCOLS .SH PROTOCOLS
All All
.SH EXAMPLE .SH EXAMPLE
TODO .nf
curl = curl_easy_init();
if(curl) {
/* pass in the URL from an external source */
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
/* only allow HTTP, TFTP and SFTP */
curl_easy_setopt(curl, CURLOPT_PROTOCOLS,
CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);
/* Perform the request */
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Added in 7.19.4 Added in 7.19.4
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -34,12 +34,55 @@ redirect when \fICURLOPT_FOLLOWLOCATION(3)\fP is enabled. This allows you to
limit specific transfers to only be allowed to use a subset of protocols in limit specific transfers to only be allowed to use a subset of protocols in
redirections. By default libcurl will allow all protocols except for FILE and redirections. By default libcurl will allow all protocols except for FILE and
SCP. SCP.
These are the available protocol defines:
.nf
CURLPROTO_DICT
CURLPROTO_FILE
CURLPROTO_FTP
CURLPROTO_FTPS
CURLPROTO_GOPHER
CURLPROTO_HTTP
CURLPROTO_HTTPS
CURLPROTO_IMAP
CURLPROTO_IMAPS
CURLPROTO_LDAP
CURLPROTO_LDAPS
CURLPROTO_POP3
CURLPROTO_POP3S
CURLPROTO_RTMP
CURLPROTO_RTMPE
CURLPROTO_RTMPS
CURLPROTO_RTMPT
CURLPROTO_RTMPTE
CURLPROTO_RTMPTS
CURLPROTO_RTSP
CURLPROTO_SCP
CURLPROTO_SFTP
CURLPROTO_SMTP
CURLPROTO_SMTPS
CURLPROTO_TELNET
CURLPROTO_TFTP
.fi
.SH DEFAULT .SH DEFAULT
All protocols except for FILE and SCP All protocols except for FILE and SCP
.SH PROTOCOLS .SH PROTOCOLS
All All
.SH EXAMPLE .SH EXAMPLE
TODO .nf
curl = curl_easy_init();
if(curl) {
/* pass in the URL from an external source */
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
/* only allow redirects to HTTP and HTTPS URLs */
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS,
CURLPROTO_HTTP | CURLPROTO_HTTPS);
/* Perform the request */
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
Added in 7.19.4, before then it would follow all protocols. Added in 7.19.4, before then it would follow all protocols.
.SH RETURN VALUE .SH RETURN VALUE

View File

@ -272,12 +272,23 @@ performed.
All All
.SH EXAMPLE .SH EXAMPLE
.nf .nf
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com"); CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY .SH AVAILABILITY
POP3 and SMTP added in 7.31.0 POP3 and SMTP were added in 7.31.0
.SH RETURN VALUE .SH RETURN VALUE
Returns CURLE_OK on success or Returns CURLE_OK on success or CURLE_OUT_OF_MEMORY if there was insufficient
CURLE_OUT_OF_MEMORY if there was insufficient heap space. heap space.
Note that \fIcurl_easy_setopt(3)\fP won't actually parse the given string so
given a bad URL, it will not be detected until \fIcurl_easy_perform(3)\fP or
similar is called.
.SH "SEE ALSO" .SH "SEE ALSO"
.BR CURLOPT_VERBOSE "(3), " CURLOPT_PROTOCOLS "(3), " .BR CURLOPT_VERBOSE "(3), " CURLOPT_PROTOCOLS "(3), "
.BR CURLOPT_FORBID_REUSE "(3), " CURLOPT_FRESH_CONNECT "(3), "
.BR curl_easy_perform "(3)" .BR curl_easy_perform "(3)"

View File

@ -40,7 +40,24 @@ To also get all the protocol data sent and received, consider using the
\fICURLOPT_DEBUGFUNCTION(3)\fP. \fICURLOPT_DEBUGFUNCTION(3)\fP.
.SH DEFAULT .SH DEFAULT
0, meaning disabled. 0, meaning disabled.
.SH PROTOCOLS
All
.SH EXAMPLE
.nf
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* ask libcurl to show us the verbose output */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* Perform the request */
curl_easy_perform(curl);
}
.fi
.SH AVAILABILITY
Always
.SH RETURN VALUE .SH RETURN VALUE
Returns CURLE_OK. Returns CURLE_OK
.SH "SEE ALSO" .SH "SEE ALSO"
.BR CURLOPT_STDERR "(3), " CURLOPT_DEBUGFUNCTION "(3), " .BR CURLOPT_STDERR "(3), " CURLOPT_DEBUGFUNCTION "(3), "