CURL 上下文选项
  CURL 上下文选项 — CURL 上下文选项列表
  
 
 
  说明
  
   CURL 上下文选项在
   CURL 扩展被编译(通过
   --with-curlwrappers configure选项)时可用
  
  
 
  可选项
  
   
- 
      methodstring
- 
      
       GET,POST,或者其他远程服务器支持的 HTTP 方法。
 
       默认为 GET.
 
- 
      
       额外的请求标头。这个值会覆盖通过其他选项设定的值(如:
       User-agent:,Host:,
       ,Authentication:)。
 
- 
      user_agentstring
- 
      
       设置请求时 User-Agent 标头的值。
       
       默认为 php.ini 中的
       user_agent
       设定。
       
- 
      contentstring
- 
      
       在头部之后发送的额外数据。这个选项在
       GET和HEAD请求中不使用。
 
- 
      proxystring
- 
      
       URI,用于指定代理服务器的地址(例如
       tcp://proxy.example.com:5100)。
 
- 
      max_redirectsint
- 
      
       最大重定向次数。1或者更小则代表不会跟随重定向。
 
       默认为 20.
 
- 
      curl_verify_ssl_hostbool
- 
      
       校验服务器。
       
       默认为 false
 注意: 
        
        这个选项在 HTTP 和 FTP 协议中均可使用。
        
 
- 
      curl_verify_ssl_peerbool
- 
      
       要求对使用的SSL证书进行校验。
       
       默认为 false
 注意: 
        
        这个选项在 HTTP 和 FTP 协议中均可使用。
        
 
 
 
 
  范例
  
   
    示例 #1 获取一个页面,并以POST发送数据
    
<?php
$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);
?>