CURL context options
CURL 上下文选项列表
说明
CURL 上下文选项在CURL扩展被编译(通过--with-curlwrappers configure选项)时可用
可选项
- $methodstring
GET
,POST
,或者其他远程服务器支持的 HTTP 方法。默认为
GET
.- $headerstring
额外的请求标头。这个值会覆盖通过其他选项设定的值(如:User-agent:,Host:,,Authentication:)。
- $user_agentstring
设置请求时 User-Agent 标头的值。
默认为php.ini中的user_agent设定。
- $contentstring
在头部之后发送的额外数据。这个选项在
GET
和HEAD
请求中不使用。- $proxystring
URI,用于指定代理服务器的地址(例如tcp://proxy.example.com:5100)。
- $max_redirectsinteger
最大重定向次数。1或者更小则代表不会跟随重定向。
默认为20.
- $curl_verify_ssl_hostboolean
校验服务器。
默认为
FALSE
Note:
这个选项在 HTTP 和 FTP 协议中均可使用。
- $curl_verify_ssl_peerboolean
要求对使用的SSL证书进行校验。
默认为
FALSE
Note:
这个选项在 HTTP 和 FTP 协议中均可使用。
范例
Example #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); ?>
参见
- 套接字上下文选项