CURL context options
CURL context options — CURL 上下文选项列表
CURL 上下文选项在 CURL 扩展被编译(通过 --with-curlwrappers configure选项)时可用
method
string GET
, POST
,或者其他远程服务器支持的 HTTP 方法。
默认为 GET
.
header
string 额外的请求标头。这个值会覆盖通过其他选项设定的值(如: User-agent:,Host:, ,Authentication:)。
user_agent
string 设置请求时 User-Agent 标头的值。
默认为 php.ini 中的 user_agent 设定。
content
string
在头部之后发送的额外数据。这个选项在
GET
和 HEAD
请求中不使用。
proxy
string URI,用于指定代理服务器的地址(例如 tcp://proxy.example.com:5100)。
max_redirects
integer 最大重定向次数。1 或者更小则代表不会跟随重定向。
默认为 20.
curl_verify_ssl_host
boolean 校验服务器。
默认为 FALSE
Note:
这个选项在 HTTP 和 FTP 协议中均可使用。
curl_verify_ssl_peer
boolean 要求对使用的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 );
?>