mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
2041 lines
91 KiB
HTML
2041 lines
91 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
<title>设置 cURL 传输选项</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.curl-setopt" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">curl_setopt</h1>
|
||
<p class="verinfo">(PHP 4 >= 4.0.2, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">curl_setopt</span> — <span class="dc-title">设置 cURL 传输选项</span></p>
|
||
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.curl-setopt-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>curl_setopt</strong></span>
|
||
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$ch</code></span>
|
||
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></span>
|
||
, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
|
||
) : <span class="type">bool</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
为 cURL 会话句柄设置选项。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.curl-setopt-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
<dt>
|
||
<code class="parameter">ch</code>
|
||
</dt>
|
||
<dd>
|
||
<p class="para">由 <span class="function"><a href="curl_init.html" class="function">curl_init()</a></span> 返回的 cURL 句柄。</p></dd>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">option</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
需要设置的<em>CURLOPT_XXX</em>选项。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">value</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
将设置在<code class="parameter">option</code>选项上的值。
|
||
</p>
|
||
<p class="para">
|
||
以下 <code class="parameter">option</code> 参数的 <code class="parameter">value</code>应该被设置成 <span class="type"><a href="language.types.boolean.html" class="type bool">bool</a></span> 类型:
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>选项</th>
|
||
<th>将 <code class="parameter">value</code> 设置为</th>
|
||
<th>备注</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_AUTOREFERER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时将根据 <em>Location:</em> 重定向时,自动设置 header 中的<em>Referer:</em>信息。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_BINARYTRANSFER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设为 <strong><code>TRUE</code></strong> ,将在启用 <strong><code>CURLOPT_RETURNTRANSFER</code></strong> 时,返回原生的(Raw)输出。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
从 PHP 5.1.3 开始,此选项不再有效果:使用
|
||
<strong><code>CURLOPT_RETURNTRANSFER</code></strong> 后总是会返回原生的(Raw)内容。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_COOKIESESSION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设为 <strong><code>TRUE</code></strong> 时将开启新的一次 cookie 会话。它将强制 libcurl 忽略之前会话时存的其他 cookie。
|
||
libcurl 在默认状况下无论是否为会话,都会储存、加载所有 cookie。会话 cookie 是指没有过期时间,只存活在会话之中。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CERTINFO</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 将在安全传输时输出 SSL 证书信息到 <em>STDERR</em>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.19.1 中添加。
|
||
PHP 5.3.2 后有效。
|
||
需要开启 <strong><code>CURLOPT_VERBOSE</code></strong> 才有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CONNECT_ONLY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 将让库执行所有需要的代理、验证、连接过程,但不传输数据。此选项用于
|
||
HTTP、SMTP 和 POP3。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 7.15.2 中添加。
|
||
PHP 5.5.0 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CRLF</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
启用时将Unix的换行符转换成回车换行符。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_DNS_USE_GLOBAL_CACHE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 会启用一个全局的DNS缓存。此选项非线程安全的,默认已开启。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FAILONERROR</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
当 HTTP 状态码大于等于 400,<strong><code>TRUE</code></strong> 将将显示错误详情。 默认情况下将返回页面,忽略 HTTP 代码。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_FALSESTART</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 开启 TLS False Start (一种 TLS 握手优化方式)
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.42.0 中添加。自 PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FILETIME</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时,会尝试获取远程文档中的修改时间信息。
|
||
信息可通过<span class="function"><a href="curl_getinfo.html" class="function">curl_getinfo()</a></span>函数的<code class="parameter">CURLINFO_FILETIME</code> 选项获取。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FOLLOWLOCATION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时将会根据服务器返回 HTTP 头中的 <em>"Location: "</em> 重定向。(注意:这是递归的,<em>"Location: "</em> 发送几次就重定向几次,除非设置了 <strong><code>CURLOPT_MAXREDIRS</code></strong>,限制最大重定向次数。)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FORBID_REUSE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 在完成交互以后强制明确的断开连接,不能在连接池中重用。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FRESH_CONNECT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 强制获取一个新的连接,而不是缓存中的连接。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTP_USE_EPRT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时,当 FTP 下载时,使用 EPRT (和 LPRT)命令。 设置为 <strong><code>FALSE</code></strong> 时禁用 EPRT 和 LPRT,仅仅使用PORT 命令。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTP_USE_EPSV</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时,在FTP传输过程中,回到 PASV 模式前,先尝试 EPSV 命令。设置为 <strong><code>FALSE</code></strong> 时禁用 EPSV。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTP_CREATE_MISSING_DIRS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时,当 ftp 操作不存在的目录时将创建它。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTPAPPEND</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 为追加写入文件,而不是覆盖。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TCP_NODELAY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时禁用 TCP 的 Nagle 算法,就是减少网络上的小包数量。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
PHP 5.2.1 有效,编译时需要 libcurl 7.11.2 及以上。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTPASCII</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>CURLOPT_TRANSFERTEXT</code></strong> 的别名。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTPLISTONLY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时只列出 FTP 目录的名字。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HEADER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
启用时会将头文件的信息作为数据流输出。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>CURLINFO_HEADER_OUT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时追踪句柄的请求字符串。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
从 PHP 5.1.3 开始可用。<strong><code>CURLINFO_</code></strong> 的前缀是有意的(intentional)。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HTTPGET</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时会设置 HTTP 的 method 为 GET,由于默认是 GET,所以只有 method 被修改时才需要这个选项。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HTTPPROXYTUNNEL</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 会通过指定的 HTTP 代理来传输。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_MUTE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时将完全静默,无论是何 cURL 函数。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.15.5 中移出(可以使用 CURLOPT_RETURNTRANSFER 作为代替)
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_NETRC</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时,在连接建立时,访问<var class="filename">~/.netrc</var>文件获取用户名和密码来连接远程站点。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_NOBODY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时将不输出 BODY 部分。同时 Mehtod 变成了 HEAD。修改为 <strong><code>FALSE</code></strong> 时不会变成 GET。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_NOPROGRESS</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
<strong><code>TRUE</code></strong> 时关闭 cURL 的传输进度。
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
PHP 默认自动设置此选项为 <strong><code>TRUE</code></strong>,只有为了调试才需要改变设置。
|
||
</p>
|
||
</p></blockquote>
|
||
</p></td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_NOSIGNAL</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时忽略所有的 cURL 传递给 PHP 进行的信号。在 SAPI 多线程传输时此项被默认启用,所以超时选项仍能使用。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.10时被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PATH_AS_IS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 不处理 dot dot sequences (即 ../ )
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.42.0 时被加入。 PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PIPEWAIT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 则等待 pipelining/multiplexing。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.43.0 时被加入。 PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_POST</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时会发送 POST 请求,类型为:<em>application/x-www-form-urlencoded</em>,是 HTML 表单提交时最常见的一种。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PUT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 时允许 HTTP 发送文件。要被 PUT 的文件必须在 <strong><code>CURLOPT_INFILE</code></strong>和<strong><code>CURLOPT_INFILESIZE</code></strong> 中设置。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_RETURNTRANSFER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 将<span class="function"><a href="curl_exec.html" class="function">curl_exec()</a></span>获取的信息以字符串返回,而不是直接输出。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SAFE_UPLOAD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 禁用 <em>@</em> 前缀在 <strong><code>CURLOPT_POSTFIELDS</code></strong> 中发送文件。
|
||
|
||
意味着 <em>@</em> 可以在字段中安全得使用了。
|
||
可使用 <a href="class.curlfile.html" class="classname">CURLFile</a> 作为上传的代替。
|
||
</td>
|
||
|
||
|
||
|
||
|
||
<td style="vertical-align: top;">
|
||
PHP 5.5.0 中添加,默认值 <strong><code>FALSE</code></strong>。
|
||
PHP 5.6.0 改默认值为 <strong><code>TRUE</code></strong>。.
|
||
PHP 7 删除了此选项, 必须使用 CURLFile interface 来上传文件。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SASL_IR</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 开启,收到首包(first packet)后发送初始的响应(initial response)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.31.10 中添加,自 PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_ENABLE_ALPN</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>FALSE</code></strong> 禁用 SSL 握手中的 ALPN (如果 SSL 后端的
|
||
libcurl 内建支持) 用于协商到 http2。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.36.0 中增加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_ENABLE_NPN</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>FALSE</code></strong> 禁用 SSL 握手中的 NPN(如果 SSL 后端的
|
||
libcurl 内建支持),用于协商到 http2。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.36.0 中增加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_VERIFYPEER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>FALSE</code></strong> 禁止 cURL 验证对等证书(peer's
|
||
certificate)。要验证的交换证书可以在 <strong><code>CURLOPT_CAINFO</code></strong> 选项中设置,或在 <strong><code>CURLOPT_CAPATH</code></strong>中设置证书目录。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
自cURL 7.10开始默认为 <strong><code>TRUE</code></strong>。从 cURL 7.10开始默认绑定安装。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_VERIFYSTATUS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 验证证书状态。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.41.0 中添加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TCP_FASTOPEN</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 开启 TCP Fast Open。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.49.0 中添加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TFTP_NO_OPTIONS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 不发送 TFTP 的 options 请求。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
自 cURL 7.48.0 添加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TRANSFERTEXT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 对 FTP 传输使用 ASCII 模式。对于LDAP,它检索纯文本信息而非 HTML。在 Windows 系统上,系统不会把 <em>STDOUT</em> 设置成二进制 模式。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_UNRESTRICTED_AUTH</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 在使用<strong><code>CURLOPT_FOLLOWLOCATION</code></strong>重定向 header 中的多个 location 时继续发送用户名和密码信息,哪怕主机名已改变。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_UPLOAD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 准备上传。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_VERBOSE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>TRUE</code></strong> 会输出所有的信息,写入到<em>STDERR</em>,或在<strong><code>CURLOPT_STDERR</code></strong>中指定的文件。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
<p class="para">
|
||
以下 <code class="parameter">option</code>的<code class="parameter">value</code>应该被设置成 <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>:
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>选项</th>
|
||
<th>设置<code class="parameter">value</code>为</th>
|
||
<th>备注</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_BUFFERSIZE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
每次读入的缓冲的尺寸。当然不保证每次都会完全填满这个尺寸。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在cURL 7.10中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CLOSEPOLICY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>CURLCLOSEPOLICY_*</code></strong> 中的一个。
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
此选项已被废弃,它不会被实现,永远不会有效果啦。
|
||
</p>
|
||
</p></blockquote>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
PHP 5.6.0 中移除。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td><strong><code>CURLOPT_CONNECTTIMEOUT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
在尝试连接时等待的秒数。设置为0,则无限等待。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CONNECTTIMEOUT_MS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
尝试连接等待的时间,以毫秒为单位。设置为0,则无限等待。
|
||
|
||
如果 libcurl 编译时使用系统标准的名称解析器( standard system name resolver),那部分的连接仍旧使用以秒计的超时解决方案,最小超时时间还是一秒钟。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.16.2 中被加入。从 PHP 5.2.3 开始可用。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_DNS_CACHE_TIMEOUT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置在内存中缓存 DNS 的时间,默认为120秒(两分钟)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_EXPECT_100_TIMEOUT_MS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
超时预计: 100毫秒内的 continue 响应
|
||
默认为 1000 毫秒。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.36.0 中添加,自 PHP 7.0.7 有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTPSSLAUTH</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
FTP验证方式(启用的时候):<em>CURLFTPAUTH_SSL</em> (首先尝试SSL),<em>CURLFTPAUTH_TLS</em> (首先尝试TLS)或<em>CURLFTPAUTH_DEFAULT</em> (让cURL 自个儿决定)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.12.2 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HEADEROPT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
How to deal with headers. One of the following constants:
|
||
<span class="simpara">
|
||
<strong><code>CURLHEADER_UNIFIED</code></strong>: the headers specified in
|
||
<strong><code>CURLOPT_HTTPHEADER</code></strong> will be used in requests
|
||
both to servers and proxies. With this option enabled,
|
||
<strong><code>CURLOPT_PROXYHEADER</code></strong> will not have any effect.
|
||
</span>
|
||
<span class="simpara">
|
||
<strong><code>CURLHEADER_SEPARATE</code></strong>: makes
|
||
<strong><code>CURLOPT_HTTPHEADER</code></strong> headers only get sent to
|
||
a server and not to a proxy. Proxy headers must be set with
|
||
<strong><code>CURLOPT_PROXYHEADER</code></strong> to get used. Note that if
|
||
a non-CONNECT request is sent to a proxy, libcurl will send both
|
||
server headers and proxy headers. When doing CONNECT, libcurl will
|
||
send <strong><code>CURLOPT_PROXYHEADER</code></strong> headers only to the
|
||
proxy and then <strong><code>CURLOPT_HTTPHEADER</code></strong> headers
|
||
only to the server.
|
||
</span>
|
||
<span class="simpara">
|
||
Defaults to <strong><code>CURLHEADER_SEPARATE</code></strong> as of cURL
|
||
7.42.1, and <strong><code>CURLHEADER_UNIFIED</code></strong> before.
|
||
</span>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.37.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HTTP_VERSION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<code class="parameter">CURL_HTTP_VERSION_NONE</code> (默认值,让 cURL 自己判断使用哪个版本),<code class="parameter">CURL_HTTP_VERSION_1_0</code> (强制使用 HTTP/1.0)或<code class="parameter">CURL_HTTP_VERSION_1_1</code> (强制使用 HTTP/1.1)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HTTPAUTH</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<p class="para">
|
||
使用的 HTTP 验证方法。选项有:
|
||
<code class="parameter">CURLAUTH_BASIC</code>、
|
||
<code class="parameter">CURLAUTH_DIGEST</code>、
|
||
<code class="parameter">CURLAUTH_GSSNEGOTIATE</code>、
|
||
<code class="parameter">CURLAUTH_NTLM</code>、
|
||
<code class="parameter">CURLAUTH_ANY</code>和
|
||
<code class="parameter">CURLAUTH_ANYSAFE</code>。
|
||
</p>
|
||
<p class="para">
|
||
可以使用 <em>|</em> 位域(OR)操作符结合多个值,cURL 会让服务器选择受支持的方法,并选择最好的那个。
|
||
</p>
|
||
<p class="para">
|
||
<code class="parameter">CURLAUTH_ANY</code>是 <em>CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM</em> 的别名。
|
||
</p>
|
||
|
||
<p class="para">
|
||
<code class="parameter">CURLAUTH_ANYSAFE</code> 是 <em>CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM</em> 的别名。
|
||
</p>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_INFILESIZE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
希望传给远程站点的文件尺寸,字节(byte)为单位。
|
||
注意无法用这个选项阻止 libcurl 发送更多的数据,确切发送什么取决于 <strong><code>CURLOPT_READFUNCTION</code></strong>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_LOW_SPEED_LIMIT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
传输速度,每秒字节(bytes)数,根据<strong><code>CURLOPT_LOW_SPEED_TIME</code></strong>秒数统计是否因太慢而取消传输。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_LOW_SPEED_TIME</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
当传输速度小于<strong><code>CURLOPT_LOW_SPEED_LIMIT</code></strong>时(bytes/sec),PHP会判断是否因太慢而取消传输。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_MAXCONNECTS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
允许的最大连接数量。达到限制时,会通过<strong><code>CURLOPT_CLOSEPOLICY</code></strong>决定应该关闭哪些连接。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_MAXREDIRS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
指定最多的 HTTP 重定向次数,这个选项是和<strong><code>CURLOPT_FOLLOWLOCATION</code></strong>一起使用的。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PORT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
用来指定连接端口。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_POSTREDIR</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
位掩码, 1 (301 永久重定向), 2 (302 Found)
|
||
和 4 (303 See Other)
|
||
设置 <strong><code>CURLOPT_FOLLOWLOCATION</code></strong> 时,什么情况下需要再次 HTTP POST 到重定向网址。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.19.1 中添加,PHP 5.3.2 开始可用。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROTOCOLS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<p class="para">
|
||
<strong><code>CURLPROTO_*</code></strong>的位掩码。
|
||
启用时,会限制 libcurl 在传输过程中可使用哪些协议。
|
||
这将允许你在编译libcurl时支持众多协议,但是限制只用允许的子集。默认 libcurl 将使用所有支持的协议。
|
||
参见<strong><code>CURLOPT_REDIR_PROTOCOLS</code></strong>。
|
||
</p>
|
||
<p class="para">
|
||
可用的协议选项为:
|
||
<code class="parameter">CURLPROTO_HTTP</code>、
|
||
<code class="parameter">CURLPROTO_HTTPS</code>、
|
||
<code class="parameter">CURLPROTO_FTP</code>、
|
||
<code class="parameter">CURLPROTO_FTPS</code>、
|
||
<code class="parameter">CURLPROTO_SCP</code>、
|
||
<code class="parameter">CURLPROTO_SFTP</code>、
|
||
<code class="parameter">CURLPROTO_TELNET</code>、
|
||
<code class="parameter">CURLPROTO_LDAP</code>、
|
||
<code class="parameter">CURLPROTO_LDAPS</code>、
|
||
<code class="parameter">CURLPROTO_DICT</code>、
|
||
<code class="parameter">CURLPROTO_FILE</code>、
|
||
<code class="parameter">CURLPROTO_TFTP</code>、
|
||
<code class="parameter">CURLPROTO_ALL</code>。
|
||
</p>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.19.4 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXYAUTH</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
HTTP 代理连接的验证方式。使用在<strong><code>CURLOPT_HTTPAUTH</code></strong>中的位掩码。
|
||
当前仅仅支持 <code class="parameter">CURLAUTH_BASIC</code>和<code class="parameter">CURLAUTH_NTLM</code>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.10.7 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXYPORT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
代理服务器的端口。端口也可以在<strong><code>CURLOPT_PROXY</code></strong>中设置。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXYTYPE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
可以是 <strong><code>CURLPROXY_HTTP</code></strong> (默认值)
|
||
<strong><code>CURLPROXY_SOCKS4</code></strong>、
|
||
<strong><code>CURLPROXY_SOCKS5</code></strong>、
|
||
<strong><code>CURLPROXY_SOCKS4A</code></strong> 或
|
||
<strong><code>CURLPROXY_SOCKS5_HOSTNAME</code></strong>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.10 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_REDIR_PROTOCOLS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>CURLPROTO_*</code></strong> 值的位掩码。如果被启用,位掩码会限制 libcurl 在 <strong><code>CURLOPT_FOLLOWLOCATION</code></strong>开启时,使用的协议。
|
||
默认允许除 FILE 和 SCP 外所有协议。
|
||
这和 7.19.4 前的版本无条件支持所有支持的协议不同。关于协议常量,请参照<strong><code>CURLOPT_PROTOCOLS</code></strong>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.19.4 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_RESUME_FROM</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
在恢复传输时,传递字节为单位的偏移量(用来断点续传)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_OPTIONS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
Set SSL behavior options, which is a bitmask of any of the following constants:
|
||
<span class="simpara">
|
||
<strong><code>CURLSSLOPT_ALLOW_BEAST</code></strong>: do not attempt to use
|
||
any workarounds for a security flaw in the SSL3 and TLS1.0 protocols.
|
||
</span>
|
||
<span class="simpara">
|
||
<strong><code>CURLSSLOPT_NO_REVOKE</code></strong>: disable certificate
|
||
revocation checks for those SSL backends where such behavior is
|
||
present.
|
||
</span>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.25.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_VERIFYHOST</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置为 <em>1</em> 是检查服务器SSL证书中是否存在一个公用名(common name)。译者注:公用名(Common Name)一般来讲就是填写你将要申请SSL证书的域名 (domain)或子域名(sub domain)。
|
||
设置成 2,会检查公用名是否存在,并且是否与提供的主机名匹配。
|
||
<em>0</em> 为不检查名称。
|
||
在生产环境中,这个值应该是 <em>2</em>(默认值)。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
值 <em>1</em> 的支持在 cURL 7.28.1 中被删除了。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLVERSION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>CURL_SSLVERSION_DEFAULT</code></strong> (0),
|
||
<strong><code>CURL_SSLVERSION_TLSv1</code></strong> (1),
|
||
<strong><code>CURL_SSLVERSION_SSLv2</code></strong> (2),
|
||
<strong><code>CURL_SSLVERSION_SSLv3</code></strong> (3),
|
||
<strong><code>CURL_SSLVERSION_TLSv1_0</code></strong> (4),
|
||
<strong><code>CURL_SSLVERSION_TLSv1_1</code></strong> (5) ,
|
||
<strong><code>CURL_SSLVERSION_TLSv1_2</code></strong> (6) 中的其中一个。
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
你最好别设置这个值,让它使用默认值。
|
||
设置为 2 或 3 比较危险,在 SSLv2 和 SSLv3 中有弱点存在。
|
||
</p>
|
||
</p></blockquote>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_STREAM_WEIGHT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置 stream weight 数值 ( 1 和 256 之间的数字).
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.46.0 中添加,自 PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TIMECONDITION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置如何对待 <strong><code>CURLOPT_TIMEVALUE</code></strong>。
|
||
使用 <code class="parameter">CURL_TIMECOND_IFMODSINCE</code>,仅在页面 <strong><code>CURLOPT_TIMEVALUE</code></strong> 之后修改,才返回页面。没有修改则返回 <em>"304 Not Modified"</em> 头,假设设置了 <strong><code>CURLOPT_HEADER</code></strong> 为 <strong><code>TRUE</code></strong>。<code class="parameter">CURL_TIMECOND_IFUNMODSINCE</code>则起相反的效果。
|
||
默认为 <code class="parameter">CURL_TIMECOND_IFMODSINCE</code>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TIMEOUT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
允许 cURL 函数执行的最长秒数。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TIMEOUT_MS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置cURL允许执行的最长毫秒数。
|
||
|
||
|
||
如果 libcurl 编译时使用系统标准的名称解析器( standard system name resolver),那部分的连接仍旧使用以秒计的超时解决方案,最小超时时间还是一秒钟。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.16.2 中被加入。从 PHP 5.2.3 起可使用。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_TIMEVALUE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
秒数,从 1970年1月1日开始。这个时间会被 <strong><code>CURLOPT_TIMECONDITION</code></strong>使。默认使用<code class="parameter">CURL_TIMECOND_IFMODSINCE</code>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_MAX_RECV_SPEED_LARGE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
如果下载速度超过了此速度(以每秒字节数来统计) ,即传输过程中累计的平均数,传输就会降速到这个参数的值。默认不限速。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.15.5 中添加, PHP 5.4.0 有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_MAX_SEND_SPEED_LARGE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
如果上传的速度超过了此速度(以每秒字节数来统计),即传输过程中累计的平均数
|
||
,传输就会降速到这个参数的值。默认不限速。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.15.5 中添加, PHP 5.4.0 有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSH_AUTH_TYPES</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
A bitmask consisting of one or more of
|
||
<strong><code>CURLSSH_AUTH_PUBLICKEY</code></strong>,
|
||
<strong><code>CURLSSH_AUTH_PASSWORD</code></strong>,
|
||
<strong><code>CURLSSH_AUTH_HOST</code></strong>,
|
||
<strong><code>CURLSSH_AUTH_KEYBOARD</code></strong>. Set to
|
||
<strong><code>CURLSSH_AUTH_ANY</code></strong> to let libcurl pick one.
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.16.1 中添加。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_IPRESOLVE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
允许程序选择想要解析的 IP 地址类别。只有在地址有多种 ip 类别的时候才能用,可以的值有:
|
||
<strong><code>CURL_IPRESOLVE_WHATEVER</code></strong>、
|
||
<strong><code>CURL_IPRESOLVE_V4</code></strong>、
|
||
<strong><code>CURL_IPRESOLVE_V6</code></strong>,默认是
|
||
<strong><code>CURL_IPRESOLVE_WHATEVER</code></strong>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.10.8 中添加。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTP_FILEMETHOD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
告诉 curl 使用哪种方式来获取 FTP(s) 服务器上的文件。可能的值有:
|
||
<strong><code>CURLFTPMETHOD_MULTICWD</code></strong>、
|
||
<strong><code>CURLFTPMETHOD_NOCWD</code></strong> 和
|
||
<strong><code>CURLFTPMETHOD_SINGLECWD</code></strong>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.15.1 中添加, PHP 5.3.0 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
<p class="para">
|
||
对于下面的这些<code class="parameter">option</code>,<code class="parameter">value</code>应该被设置成 <span class="type"><a href="language.types.string.html" class="type string">string</a></span>:
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>选项</th>
|
||
<th>设置的<code class="parameter">value</code></th>
|
||
<th>备注</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CAINFO</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一个保存着1个或多个用来让服务端验证的证书的文件名。这个参数仅仅在和<strong><code>CURLOPT_SSL_VERIFYPEER</code></strong>一起使用时才有意义。 .
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
可能需要绝对路径。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CAPATH</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一个保存着多个CA证书的目录。这个选项是和<strong><code>CURLOPT_SSL_VERIFYPEER</code></strong>一起使用的。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_COOKIE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设定 HTTP 请求中<em>"Cookie: "</em>部分的内容。多个 cookie 用分号分隔,分号后带一个空格(例如, "<em>fruit=apple; colour=red</em>")。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_COOKIEFILE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
包含 cookie 数据的文件名,cookie 文件的格式可以是 Netscape 格式,或者只是纯 HTTP 头部风格,存入文件。如果文件名是空的,不会加载 cookie,但 cookie 的处理仍旧启用。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_COOKIEJAR</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
连接结束后,比如,调用 curl_close 后,保存 cookie 信息的文件。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CUSTOMREQUEST</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
HTTP 请求时,使用自定义的 Method 来代替<em>"GET"</em>或<em>"HEAD"</em>。对 <em>"DELETE"</em> 或者其他更隐蔽的 HTTP 请求有用。
|
||
有效值如 <em>"GET"</em>,<em>"POST"</em>,<em>"CONNECT"</em>等等;也就是说,不要在这里输入整行 HTTP 请求。例如输入<em>"GET /index.html HTTP/1.0\r\n\r\n"</em>是不正确的。
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
不确定服务器支持这个自定义方法则不要使用它。
|
||
</p>
|
||
</p></blockquote>
|
||
</p>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_DEFAULT_PROTOCOL</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
URL不带协议的时候,使用的默认协议。
|
||
</p></td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.45.0 中添加,自 PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_DNS_INTERFACE</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
Set the name of the network interface that the DNS resolver should bind to.
|
||
This must be an interface name (not an address).
|
||
</p></td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.33.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_DNS_LOCAL_IP4</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
Set the local IPv4 address that the resolver should bind to. The argument
|
||
should contain a single numerical IPv4 address as a string.
|
||
</p></td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.33.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_DNS_LOCAL_IP6</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
Set the local IPv6 address that the resolver should bind to. The argument
|
||
should contain a single numerical IPv6 address as a string.
|
||
</p></td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.33.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_EGDSOCKET</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
类似<strong><code>CURLOPT_RANDOM_FILE</code></strong>,除了一个Entropy Gathering Daemon套接字。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_ENCODING</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
HTTP请求头中<em>"Accept-Encoding: "</em>的值。
|
||
这使得能够解码响应的内容。
|
||
支持的编码有<em>"identity"</em>,<em>"deflate"</em>和<em>"gzip"</em>。如果为空字符串<em>""</em>,会发送所有支持的编码类型。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.10 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FTPPORT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
这个值将被用来获取供FTP"PORT"指令所需要的IP地址。
|
||
"PORT" 指令告诉远程服务器连接到我们指定的IP地址。这个字符串可以是纯文本的IP地址、主机名、一个网络接口名(UNIX下)或者只是一个'-'来使用默认的 IP 地址。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_INTERFACE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
发送的网络接口(interface),可以是一个接口名、IP 地址或者是一个主机名。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_KEYPASSWD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
使用 <strong><code>CURLOPT_SSLKEY</code></strong>
|
||
或 <strong><code>CURLOPT_SSH_PRIVATE_KEYFILE</code></strong> 私钥时候的密码。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.16.1 中添加。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_KRB4LEVEL</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
KRB4 (Kerberos 4) 安全级别。下面的任何值都是有效的(从低到高的顺序):<em>"clear"</em>、<em>"safe"</em>、<em>"confidential"</em>、<em>"private".</em>。如果字符串以上这些,将使用<em>"private"</em>。
|
||
这个选项设置为 <strong><code>NULL</code></strong> 时将禁用 KRB4 安全认证。目前 KRB4 安全认证只能用于 FTP 传输。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_LOGIN_OPTIONS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
Can be used to set protocol specific login options, such as the
|
||
preferred authentication mechanism via "AUTH=NTLM" or "AUTH=*",
|
||
and should be used in conjunction with the
|
||
<strong><code>CURLOPT_USERNAME</code></strong> option.
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.34.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PINNEDPUBLICKEY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
Set the pinned public key.
|
||
The string can be the file name of your pinned public key. The file
|
||
format expected is "PEM" or "DER". The string can also be any
|
||
number of base64 encoded sha256 hashes preceded by "sha256//" and
|
||
separated by ";".
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.39.0. Available since PHP 7.0.7.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_POSTFIELDS</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<span class="simpara">
|
||
全部数据使用HTTP协议中的 "POST" 操作来发送。
|
||
要发送文件,在文件名前面加上<em>@</em>前缀并使用完整路径。
|
||
文件类型可在文件名后以 '<em>;type=mimetype</em>' 的格式指定。
|
||
|
||
这个参数可以是 urlencoded 后的字符串,类似'<em>para1=val1&para2=val2&...</em>',也可以使用一个以字段名为键值,字段数据为值的数组。
|
||
如果<code class="parameter">value</code>是一个数组,<em>Content-Type</em>头将会被设置成<em>multipart/form-data</em>。
|
||
</span>
|
||
<span class="simpara">
|
||
从 PHP 5.2.0 开始,使用 <em>@</em> 前缀传递文件时,<code class="parameter">value</code> 必须是个数组。
|
||
</span>
|
||
<span class="simpara">
|
||
从 PHP 5.5.0 开始, <em>@</em> 前缀已被废弃,文件可通过 <a href="class.curlfile.html" class="classname">CURLFile</a> 发送。
|
||
设置 <strong><code>CURLOPT_SAFE_UPLOAD</code></strong> 为 <strong><code>TRUE</code></strong> 可禁用 <em>@</em> 前缀发送文件,以增加安全性。
|
||
</span>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PRIVATE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
Any data that should be associated with this cURL handle.
|
||
This data
|
||
can subsequently be retrieved with the
|
||
<strong><code>CURLINFO_PRIVATE</code></strong> option of
|
||
<span class="function"><a href="curl_getinfo.html" class="function">curl_getinfo()</a></span>. cURL does nothing with this data.
|
||
When using a cURL multi handle, this private data is typically a
|
||
unique key to identify a standard cURL handle.
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.10.3.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
HTTP 代理通道。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXY_SERVICE_NAME</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
代理验证服务的名称。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.34.0 中添加,PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXYUSERPWD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一个用来连接到代理的<em>"[username]:[password]"</em>格式的字符串。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_RANDOM_FILE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一个被用来生成 SSL 随机数种子的文件名。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_RANGE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
以<em>"X-Y"</em>的形式,其中X和Y都是可选项获取数据的范围,以字节计。HTTP传输线程也支持几个这样的重复项中间用逗号分隔如<em>"X-Y,N-M"</em>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_REFERER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
在HTTP请求头中<em>"Referer: "</em>的内容。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SERVICE_NAME</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
验证服务的名称
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.43.0 起添加,自 PHP 7.0.7 有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSH_HOST_PUBLIC_KEY_MD5</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
包含 32 位长的 16 进制数值。这个字符串应该是远程主机公钥(public key) 的 MD5 校验值。在不匹配的时候 libcurl 会拒绝连接。
|
||
此选项仅用于 SCP 和 SFTP 的传输。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.17.1 中添加。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSH_PUBLIC_KEYFILE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
The file name for your public key. If not used, libcurl defaults to
|
||
$HOME/.ssh/id_dsa.pub if the HOME environment variable is set,
|
||
and just "id_dsa.pub" in the current directory if HOME is not set.
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.16.1.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSH_PRIVATE_KEYFILE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
The file name for your private key. If not used, libcurl defaults to
|
||
$HOME/.ssh/id_dsa if the HOME environment variable is set,
|
||
and just "id_dsa" in the current directory if HOME is not set.
|
||
If the file is password-protected, set the password with
|
||
<strong><code>CURLOPT_KEYPASSWD</code></strong>.
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
Added in cURL 7.16.1.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSL_CIPHER_LIST</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一个SSL的加密算法列表。例如<em>RC4-SHA</em>和<em>TLSv1</em>都是可用的加密列表。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLCERT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一个包含 PEM 格式证书的文件名。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLCERTPASSWD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
使用<strong><code>CURLOPT_SSLCERT</code></strong>证书需要的密码。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLCERTTYPE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
证书的类型。支持的格式有<em>"PEM"</em> (默认值), <em>"DER"</em>和<em>"ENG"</em>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.9.3中 被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLENGINE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
用来在<strong><code>CURLOPT_SSLKEY</code></strong>中指定的SSL私钥的加密引擎变量。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLENGINE_DEFAULT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
用来做非对称加密操作的变量。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLKEY</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
包含 SSL 私钥的文件名。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLKEYPASSWD</code></strong></td>
|
||
<td style="vertical-align: top;"><p class="para">
|
||
在 <strong><code>CURLOPT_SSLKEY</code></strong>中指定了的SSL私钥的密码。
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
由于这个选项包含了敏感的密码信息,记得保证这个PHP脚本的安全。
|
||
</p>
|
||
</p></blockquote>
|
||
</p></td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SSLKEYTYPE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<strong><code>CURLOPT_SSLKEY</code></strong>中规定的私钥的加密类型,支持的密钥类型为<em>"PEM"</em>(默认值)、<em>"DER"</em>和<em>"ENG"</em>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_UNIX_SOCKET_PATH</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
使用 Unix 套接字作为连接,并用指定的 <span class="type"><a href="language.types.string.html" class="type string">string</a></span> 作为路径。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.40.0 中添加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_URL</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
需要获取的 URL 地址,也可以在<span class="function"><a href="curl_init.html" class="function">curl_init()</a></span> 初始化会话的时候。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_USERAGENT</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
在HTTP请求中包含一个<em>"User-Agent: "</em>头的字符串。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_USERNAME</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
验证中使用的用户名。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.19.1 中添加,PHP 5.5.0 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_USERPWD</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
传递一个连接中需要的用户名和密码,格式为:<em>"[username]:[password]"</em>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_XOAUTH2_BEARER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
指定 OAuth 2.0 access token。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.33.0 中添加,自 PHP 7.0.7 添加。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
<p class="para">以下<code class="parameter">option</code>,<code class="parameter">value</code>应该被设置成数组:
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>选项</th>
|
||
<th>可选<code class="parameter">value</code>值</th>
|
||
<th>备注</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_CONNECT_TO</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
连接到指定的主机和端口,替换 URL 中的主机和端口。接受指定字符串格式的数组:
|
||
<em>HOST:PORT:CONNECT-TO-HOST:CONNECT-TO-PORT</em>。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.49.0 中添加, PHP 7.0.7 起有效。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HTTP200ALIASES</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
HTTP 200 响应码数组,数组中的响应码被认为是正确的响应,而非错误。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.10.3 中被加入。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HTTPHEADER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置 HTTP 头字段的数组。格式:
|
||
<code class="code">
|
||
array('Content-type: text/plain', 'Content-length: 100')
|
||
</code>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_POSTQUOTE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
在 FTP 请求执行完成后,在服务器上执行的一组array格式的 FTP 命令。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROXYHEADER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
传给代理的自定义 HTTP 头。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
cURL 7.37.0 中添加,自 PHP 7.0.7 添加。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_QUOTE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
一组先于 FTP 请求的在服务器上执行的FTP命令。
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_RESOLVE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
提供自定义地址,指定了主机和端口。
|
||
包含主机、端口和 ip 地址的字符串,组成 array 的,每个元素以冒号分隔。格式:
|
||
<code class="code">
|
||
array("example.com:80:127.0.0.1")
|
||
</code>
|
||
</td>
|
||
<td style="vertical-align: top;">
|
||
在 cURL 7.21.3 中添加,自 PHP 5.5.0 起可用。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
<p class="para">
|
||
以下 <code class="parameter">option</code>,<code class="parameter">value</code>应该被设置成流资源
|
||
(例如使用<span class="function"><a href="fopen.html" class="function">fopen()</a></span>):
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>选项</th>
|
||
<th>可选<code class="parameter">value</code>值</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_FILE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置输出文件,默认为<em>STDOUT</em> (浏览器)。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_INFILE</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
上传文件时需要读取的文件。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_STDERR</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
错误输出的地址,取代默认的<em>STDERR</em>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_WRITEHEADER</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置 header 部分内容的写入的文件地址。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
<p class="para">
|
||
以下<code class="parameter">option</code> 的 <code class="parameter">value</code>应该是有效的函数或者闭包:
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>选项</th>
|
||
<th><code class="parameter">value</code>值</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_HEADERFUNCTION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置一个回调函数,这个函数有两个参数,第一个是cURL的资源句柄,第二个是输出的 header 数据。header数据的输出必须依赖这个函数,返回已写入的数据大小。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PASSWDFUNCTION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
设置一个回调函数,有三个参数,第一个是cURL的资源句柄,第二个是一个密码提示符,第三个参数是密码长度允许的最大值。返回密码的值。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_PROGRESSFUNCTION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
<p class="para">
|
||
设置一个回调函数,有五个参数,第一个是cURL的资源句柄,第二个是预计要下载的总字节(bytes)数。第三个是目前下载的字节数,第四个是预计传输中总上传字节数,第五个是目前上传的字节数。
|
||
</p>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
只有设置 <strong><code>CURLOPT_NOPROGRESS</code></strong>
|
||
选项为 <strong><code>FALSE</code></strong> 时才会调用这个回调函数。
|
||
</p>
|
||
</p></blockquote>
|
||
<p class="para">
|
||
返回非零值将中断传输。
|
||
传输将设置 <strong><code>CURLE_ABORTED_BY_CALLBACK</code></strong> 错误。
|
||
</p>
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_READFUNCTION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
回调函数名。该函数应接受三个参数。第一个是 cURL resource;第二个是通过选项
|
||
<strong><code>CURLOPT_INFILE</code></strong> 传给 cURL 的 stream resource;第三个参数是最大可以读取的数据的数量。回
|
||
调函数必须返回一个字符串,长度小于或等于请求的数据量(第三个参数)。一般从传入的 stream
|
||
resource 读取。返回空字符串作为 <em>EOF</em>(文件结束) 信号。
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
|
||
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_WRITEFUNCTION</code></strong></td>
|
||
<td style="vertical-align: top;">
|
||
回调函数名。该函数应接受两个参数。第一个是 cURL resource;第二个是要写入的数据字符串。数
|
||
据必须在函数中被保存。
|
||
函数必须准确返回写入数据的字节数,否则传输会被一个错误所中
|
||
断。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
<p class="para">
|
||
其他值:
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>Option</th>
|
||
<th>设置 <code class="parameter">value</code> 为</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td style="vertical-align: top;"><strong><code>CURLOPT_SHARE</code></strong></td>
|
||
<td style="vertical-align: top;"> <span class="function"><a href="curl_share_init.html" class="function">curl_share_init()</a></span> 返回的结果。
|
||
使 cURL 可以处理共享句柄里的数据。
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.curl-setopt-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
成功时返回 <strong><code>TRUE</code></strong>, 或者在失败时返回 <strong><code>FALSE</code></strong>。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 changelog" id="refsect1-function.curl-setopt-changelog">
|
||
<h3 class="title">更新日志</h3>
|
||
<p class="para">
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>版本</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
|
||
<tr>
|
||
<td>7.0.7</td>
|
||
<td>
|
||
引入 <strong><code>CURL_HTTP_VERSION_2</code></strong>、 <strong><code>CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE</code></strong>、
|
||
<strong><code>CURL_HTTP_VERSION_2TLS</code></strong>、 <strong><code>CURL_REDIR_POST_301</code></strong>、
|
||
<strong><code>CURL_REDIR_POST_302</code></strong>、 <strong><code>CURL_REDIR_POST_303</code></strong>、
|
||
<strong><code>CURL_REDIR_POST_ALL</code></strong>、 <strong><code>CURL_VERSION_KERBEROS5</code></strong>、
|
||
<strong><code>CURL_VERSION_PSL</code></strong>、 <strong><code>CURL_VERSION_UNIX_SOCKETS</code></strong>、
|
||
<strong><code>CURLAUTH_NEGOTIATE</code></strong>、 <strong><code>CURLAUTH_NTLM_WB</code></strong>、
|
||
<strong><code>CURLFTP_CREATE_DIR</code></strong>、 <strong><code>CURLFTP_CREATE_DIR_NONE</code></strong>、
|
||
<strong><code>CURLFTP_CREATE_DIR_RETRY</code></strong>、 <strong><code>CURLHEADER_SEPARATE</code></strong>、
|
||
<strong><code>CURLHEADER_UNIFIED</code></strong>、 <strong><code>CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE</code></strong>、
|
||
<strong><code>CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE</code></strong>、 <strong><code>CURLMOPT_MAX_HOST_CONNECTIONS</code></strong>、
|
||
<strong><code>CURLMOPT_MAX_PIPELINE_LENGTH</code></strong>、 <strong><code>CURLMOPT_MAX_TOTAL_CONNECTIONS</code></strong>、
|
||
<strong><code>CURLOPT_CONNECT_TO</code></strong>、 <strong><code>CURLOPT_DEFAULT_PROTOCOL</code></strong>、
|
||
<strong><code>CURLOPT_DNS_INTERFACE</code></strong>、 <strong><code>CURLOPT_DNS_LOCAL_IP4</code></strong>、
|
||
<strong><code>CURLOPT_DNS_LOCAL_IP6</code></strong>、 <strong><code>CURLOPT_EXPECT_100_TIMEOUT_MS</code></strong>、
|
||
<strong><code>CURLOPT_HEADEROPT</code></strong>、 <strong><code>CURLOPT_LOGIN_OPTIONS</code></strong>、
|
||
<strong><code>CURLOPT_PATH_AS_IS</code></strong>、 <strong><code>CURLOPT_PINNEDPUBLICKEY</code></strong>、
|
||
<strong><code>CURLOPT_PIPEWAIT</code></strong>、 <strong><code>CURLOPT_PROXY_SERVICE_NAME</code></strong>、
|
||
<strong><code>CURLOPT_PROXYHEADER</code></strong>、 <strong><code>CURLOPT_SASL_IR</code></strong>、
|
||
<strong><code>CURLOPT_SERVICE_NAME</code></strong>、 <strong><code>CURLOPT_SSL_ENABLE_ALPN</code></strong>、
|
||
<strong><code>CURLOPT_SSL_ENABLE_NPN</code></strong>、 <strong><code>CURLOPT_SSL_FALSESTART</code></strong>、
|
||
<strong><code>CURLOPT_SSL_VERIFYSTATUS</code></strong>、 <strong><code>CURLOPT_STREAM_WEIGHT</code></strong>、
|
||
<strong><code>CURLOPT_TCP_FASTOPEN</code></strong>、 <strong><code>CURLOPT_TFTP_NO_OPTIONS</code></strong>、
|
||
<strong><code>CURLOPT_UNIX_SOCKET_PATH</code></strong>、 <strong><code>CURLOPT_XOAUTH2_BEARER</code></strong>、
|
||
<strong><code>CURLPROTO_SMB</code></strong>、 <strong><code>CURLPROTO_SMBS</code></strong>、
|
||
<strong><code>CURLPROXY_HTTP_1_0</code></strong>、 <strong><code>CURLSSH_AUTH_AGENT</code></strong> 和
|
||
<strong><code>CURLSSLOPT_NO_REVOKE</code></strong>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>7.0.0</td>
|
||
<td>
|
||
禁用 <strong><code>CURLOPT_SAFE_UPLOAD</code></strong> 的选项已被删掉了。
|
||
所有的 curl 文件的上传都必须使用 <a href="class.curlfile.html" class="classname">CURLFile</a>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.6.0</td>
|
||
<td>
|
||
默认 <strong><code>CURLOPT_SAFE_UPLOAD</code></strong>为 <strong><code>TRUE</code></strong> 。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.6.0</td>
|
||
<td>
|
||
移出 <strong><code>CURLOPT_CLOSEPOLICY</code></strong>和相关的值。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.5.0</td>
|
||
<td>
|
||
添加 cURL 资源作为 <strong><code>CURLOPT_PROGRESSFUNCTION</code></strong> 回调函数的第一个参数。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.5.0</td>
|
||
<td>
|
||
引入 <strong><code>CURLOPT_SHARE</code></strong>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.3.0</td>
|
||
<td>
|
||
引入 <strong><code>CURLOPT_PROGRESSFUNCTION</code></strong>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.2.10</td>
|
||
<td>
|
||
引入 <strong><code>CURLOPT_PROTOCOLS</code></strong>, and
|
||
<strong><code>CURLOPT_REDIR_PROTOCOLS</code></strong>.
|
||
</td>
|
||
</tr>
|
||
|
||
|
||
<tr>
|
||
<td>5.2.4</td>
|
||
<td>
|
||
引入了 <strong><code>CURLOPT_PRIVATE</code></strong>。
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.1.0</td>
|
||
<td>
|
||
引入 <strong><code>CURLOPT_AUTOREFERER</code></strong>,
|
||
<strong><code>CURLOPT_BINARYTRANSFER</code></strong>,
|
||
<strong><code>CURLOPT_FTPSSLAUTH</code></strong>,
|
||
<strong><code>CURLOPT_PROXYAUTH</code></strong>, and
|
||
<strong><code>CURLOPT_TIMECONDITION</code></strong>.
|
||
</td>
|
||
</tr>
|
||
|
||
<tr>
|
||
<td>5.0.0</td>
|
||
<td>
|
||
引入 <strong><code>CURLOPT_FTP_USE_EPRT</code></strong>,
|
||
<strong><code>CURLOPT_NOSIGNAL</code></strong>,
|
||
<strong><code>CURLOPT_UNRESTRICTED_AUTH</code></strong>,
|
||
<strong><code>CURLOPT_BUFFERSIZE</code></strong>,
|
||
<strong><code>CURLOPT_HTTPAUTH</code></strong>,
|
||
<strong><code>CURLOPT_PROXYPORT</code></strong>,
|
||
<strong><code>CURLOPT_PROXYTYPE</code></strong>,
|
||
<strong><code>CURLOPT_SSLCERTTYPE</code></strong>, and
|
||
<strong><code>CURLOPT_HTTP200ALIASES</code></strong>.
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.curl-setopt-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="example-5252">
|
||
<p><strong>Example #1 初始化一个新的cURL会话并获取一个网页</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// 创建一个新cURL资源<br /></span><span style="color: #0000BB">$ch </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_init</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// 设置URL和相应的选项<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_URL</span><span style="color: #007700">, </span><span style="color: #DD0000">"http://www.example.com/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_HEADER</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 抓取URL并把它传递给浏览器<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//关闭cURL资源,并且释放系统资源<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
<p class="para">
|
||
<div class="example" id="example-5253">
|
||
<p><strong>Example #2 上传文件 (PHP 5.5.0 后被废弃)</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">/* http://localhost/upload.php:<br />print_r($_POST);<br />print_r($_FILES);<br />*/<br /><br /></span><span style="color: #0000BB">$ch </span><span style="color: #007700">= </span><span style="color: #0000BB">curl_init</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'name' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'file' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'@/home/user/test.png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_URL</span><span style="color: #007700">, </span><span style="color: #DD0000">'http://localhost/upload.php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_POST</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_SAFE_UPLOAD</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">); </span><span style="color: #FF8000">// PHP 5.6.0 后必须开启<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">, </span><span style="color: #0000BB">CURLOPT_POSTFIELDS</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
<div class="example-contents"><p>以上例程会输出:</p></div>
|
||
<div class="example-contents screen">
|
||
<div class="cdata"><pre>
|
||
Array
|
||
(
|
||
[name] => Foo
|
||
)
|
||
Array
|
||
(
|
||
[file] => Array
|
||
(
|
||
[name] => test.png
|
||
[type] => image/png
|
||
[tmp_name] => /tmp/phpcpjNeQ
|
||
[error] => 0
|
||
[size] => 279
|
||
)
|
||
|
||
)
|
||
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 notes" id="refsect1-function.curl-setopt-notes">
|
||
<h3 class="title">注释</h3>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
传递一个数组到<strong><code>CURLOPT_POSTFIELDS</code></strong>,cURL会把数据编码成
|
||
<em class="emphasis">multipart/form-data</em>,而然传递一个URL-encoded字符串时,数据会被编码成
|
||
<em class="emphasis">application/x-www-form-urlencoded</em>。
|
||
</p>
|
||
</p></blockquote>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.curl-setopt-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="curl_setopt_array.html" class="function" rel="rdfs-seeAlso">curl_setopt_array()</a> - 为 cURL 传输会话批量设置选项</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |