<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.curl.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.curl-setopt.php',
    1 => 'curl_setopt',
    2 => '设置 cURL 传输选项',
  ),
  'up' => 
  array (
    0 => 'ref.curl.php',
    1 => 'cURL 函数',
  ),
  'prev' => 
  array (
    0 => 'function.curl-reset.php',
    1 => 'curl_reset',
  ),
  'next' => 
  array (
    0 => 'function.curl-setopt-array.php',
    1 => 'curl_setopt_array',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/curl/functions/curl-setopt.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.curl-setopt" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_setopt</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.2, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">curl_setopt</span> &mdash; <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"><a href="class.curlhandle.php" class="type CurlHandle">CurlHandle</a></span> <code class="parameter">$handle</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$option</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></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">handle</code>
</dt><dd><p class="para">由 <span class="function"><a href="function.curl-init.php" class="function">curl_init()</a></span> 返回的 cURL 句柄。</p></dd>
    
     <dt><code class="parameter">option</code></dt>
     <dd>
      <p class="para">
       需要设置的 <strong><code><a href="curl.constants.php#constant.curlopt-abstract-unix-socket">CURLOPT_<span class="replaceable">*</span></a></code></strong> 选项。
      </p>
     </dd>
    
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       将设置在 <code class="parameter">option</code> 选项上的值。有关每个常量期望的值类型的详情，请参阅
       <strong><code><a href="curl.constants.php#constant.curlopt-abstract-unix-socket">CURLOPT_<span class="replaceable">*</span></a></code></strong> 常量的描述。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-setopt-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>， 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></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>8.4.0</td>
       <td>
        <strong><code><a href="curl.constants.php#constant.curlopt-dns-use-global-cache">CURLOPT_DNS_USE_GLOBAL_CACHE</a></code></strong> 
        不再有任何效果，并且在线程安全 PHP 上启用不再触发警告。
       </td>
      </tr>

      <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">handle</code> 现在接受 <span class="classname"><a href="class.curlhandle.php" class="classname">CurlHandle</a></span>
  实例；之前接受 <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>。
 </td>
</tr>

      <tr>
       <td>7.3.15、7.4.3</td>
       <td>
        引入 <strong><code><a href="curl.constants.php#constant.curlopt-http09-allowed">CURLOPT_HTTP09_ALLOWED</a></code></strong>。
       </td>
      </tr>

      <tr>
       <td>7.3.0</td>
       <td>
        引入 <strong><code><a href="curl.constants.php#constant.curlopt-abstract-unix-socket">CURLOPT_ABSTRACT_UNIX_SOCKET</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-keep-sending-on-error">CURLOPT_KEEP_SENDING_ON_ERROR</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-pre-proxy">CURLOPT_PRE_PROXY</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-cainfo">CURLOPT_PROXY_CAINFO</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-capath">CURLOPT_PROXY_CAPATH</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-crlfile">CURLOPT_PROXY_CRLFILE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-keypasswd">CURLOPT_PROXY_KEYPASSWD</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-pinnedpublickey">CURLOPT_PROXY_PINNEDPUBLICKEY</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-sslcert">CURLOPT_PROXY_SSLCERT</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-sslcerttype">CURLOPT_PROXY_SSLCERTTYPE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-ssl-cipher-list">CURLOPT_PROXY_SSL_CIPHER_LIST</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-sslkey">CURLOPT_PROXY_SSLKEY</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-sslkeytype">CURLOPT_PROXY_SSLKEYTYPE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-ssl-options">CURLOPT_PROXY_SSL_OPTIONS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-ssl-verifyhost">CURLOPT_PROXY_SSL_VERIFYHOST</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-ssl-verifypeer">CURLOPT_PROXY_SSL_VERIFYPEER</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-sslversion">CURLOPT_PROXY_SSLVERSION</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-tlsauth-password">CURLOPT_PROXY_TLSAUTH_PASSWORD</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-tlsauth-type">CURLOPT_PROXY_TLSAUTH_TYPE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-tlsauth-username">CURLOPT_PROXY_TLSAUTH_USERNAME</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-socks5-auth">CURLOPT_SOCKS5_AUTH</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-suppress-connect-headers">CURLOPT_SUPPRESS_CONNECT_HEADERS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-disallow-username-in-url">CURLOPT_DISALLOW_USERNAME_IN_URL</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-dns-shuffle-addresses">CURLOPT_DNS_SHUFFLE_ADDRESSES</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-happy-eyeballs-timeout-ms">CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-haproxyprotocol">CURLOPT_HAPROXYPROTOCOL</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-tls13-ciphers">CURLOPT_PROXY_TLS13_CIPHERS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-ssh-compression">CURLOPT_SSH_COMPRESSION</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-timevalue-large">CURLOPT_TIMEVALUE_LARGE</a></code></strong>
        和 <strong><code><a href="curl.constants.php#constant.curlopt-tls13-ciphers">CURLOPT_TLS13_CIPHERS</a></code></strong>。
       </td>
      </tr>

      <tr>
       <td>7.0.7</td>
       <td>
        引入 <strong><code><a href="curl.constants.php#constant.curl-http-version-2">CURL_HTTP_VERSION_2</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curl-http-version-2-prior-knowledge">CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curl-http-version-2tls">CURL_HTTP_VERSION_2TLS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curl-redir-post-301">CURL_REDIR_POST_301</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curl-redir-post-302">CURL_REDIR_POST_302</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curl-redir-post-303">CURL_REDIR_POST_303</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curl-redir-post-all">CURL_REDIR_POST_ALL</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curl-version-kerberos5">CURL_VERSION_KERBEROS5</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curl-version-psl">CURL_VERSION_PSL</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curl-version-unix-sockets">CURL_VERSION_UNIX_SOCKETS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlauth-negotiate">CURLAUTH_NEGOTIATE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlauth-ntlm-wb">CURLAUTH_NTLM_WB</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlftp-create-dir">CURLFTP_CREATE_DIR</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlftp-create-dir-none">CURLFTP_CREATE_DIR_NONE</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlftp-create-dir-retry">CURLFTP_CREATE_DIR_RETRY</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlheader-separate">CURLHEADER_SEPARATE</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlheader-unified">CURLHEADER_UNIFIED</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlmopt-chunk-length-penalty-size">CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlmopt-content-length-penalty-size">CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlmopt-max-host-connections">CURLMOPT_MAX_HOST_CONNECTIONS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlmopt-max-pipeline-length">CURLMOPT_MAX_PIPELINE_LENGTH</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlmopt-max-total-connections">CURLMOPT_MAX_TOTAL_CONNECTIONS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-connect-to">CURLOPT_CONNECT_TO</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-default-protocol">CURLOPT_DEFAULT_PROTOCOL</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-dns-interface">CURLOPT_DNS_INTERFACE</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-dns-local-ip4">CURLOPT_DNS_LOCAL_IP4</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-dns-local-ip6">CURLOPT_DNS_LOCAL_IP6</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-expect-100-timeout-ms">CURLOPT_EXPECT_100_TIMEOUT_MS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-headeropt">CURLOPT_HEADEROPT</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-login-options">CURLOPT_LOGIN_OPTIONS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-path-as-is">CURLOPT_PATH_AS_IS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-pinnedpublickey">CURLOPT_PINNEDPUBLICKEY</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-pipewait">CURLOPT_PIPEWAIT</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-proxy-service-name">CURLOPT_PROXY_SERVICE_NAME</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-proxyheader">CURLOPT_PROXYHEADER</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-sasl-ir">CURLOPT_SASL_IR</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-service-name">CURLOPT_SERVICE_NAME</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-ssl-enable-alpn">CURLOPT_SSL_ENABLE_ALPN</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-ssl-enable-npn">CURLOPT_SSL_ENABLE_NPN</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-ssl-falsestart">CURLOPT_SSL_FALSESTART</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-ssl-verifystatus">CURLOPT_SSL_VERIFYSTATUS</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-stream-weight">CURLOPT_STREAM_WEIGHT</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-tcp-fastopen">CURLOPT_TCP_FASTOPEN</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-tftp-no-options">CURLOPT_TFTP_NO_OPTIONS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlopt-unix-socket-path">CURLOPT_UNIX_SOCKET_PATH</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlopt-xoauth2-bearer">CURLOPT_XOAUTH2_BEARER</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlproto-smb">CURLPROTO_SMB</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlproto-smbs">CURLPROTO_SMBS</a></code></strong>、
        <strong><code><a href="curl.constants.php#constant.curlproxy-http-1-0">CURLPROXY_HTTP_1_0</a></code></strong>、<strong><code><a href="curl.constants.php#constant.curlssh-auth-agent">CURLSSH_AUTH_AGENT</a></code></strong> 和
        <strong><code><a href="curl.constants.php#constant.curlsslopt-no-revoke">CURLSSLOPT_NO_REVOKE</a></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-1">
    <p><strong>示例 #1 初始化一个新的cURL会话并获取一个网页</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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 /></span><span style="color: #0000BB">?&gt;</span></span></code></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">注意</strong>: 
   <p class="para">
    传递一个数组到<strong><code><a href="curl.constants.php#constant.curlopt-postfields">CURLOPT_POSTFIELDS</a></code></strong>，cURL会把数据编码成
    <em>multipart/form-data</em>，而然传递一个URL-encoded字符串时，数据会被编码成
    <em>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><span class="function"><a href="function.curl-setopt-array.php" class="function" rel="rdfs-seeAlso">curl_setopt_array()</a> - 为 cURL 传输会话批量设置选项</span></li>
    <li><span class="classname"><a href="class.curlfile.php" class="classname">CURLFile</a></span></li>
    <li><span class="classname"><a href="class.curlstringfile.php" class="classname">CURLStringFile</a></span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>