CURL 上下文選項(xiàng)

CURL 上下文選項(xiàng)CURL 上下文選項(xiàng)列表

說明

CURL 上下文選項(xiàng)在 CURL 擴(kuò)展被編譯(通過 --with-curlwrappers configure選項(xiàng))時可用

可選項(xiàng)

method string

GET,POST,或者其他遠(yuǎn)程服務(wù)器支持的 HTTP 方法。

默認(rèn)為 GET.

header string

額外的請求標(biāo)頭。這個值會覆蓋通過其他選項(xiàng)設(shè)定的值(如: User-agent:,Host:, ,Authentication:)。

user_agent string

設(shè)置請求時 User-Agent 標(biāo)頭的值。

默認(rèn)為 php.ini 中的 user_agent 設(shè)定。

content string

在頭部之后發(fā)送的額外數(shù)據(jù)。這個選項(xiàng)在 GETHEAD 請求中不使用。

proxy string

URI,用于指定代理服務(wù)器的地址(例如 tcp://proxy.example.com:5100)。

max_redirects int

最大重定向次數(shù)。1 或者更小則代表不會跟隨重定向。

默認(rèn)為 20.

curl_verify_ssl_host bool

校驗(yàn)服務(wù)器。

默認(rèn)為 false

注意:

這個選項(xiàng)在 HTTP 和 FTP 協(xié)議中均可使用。

curl_verify_ssl_peer bool

要求對使用的SSL證書進(jìn)行校驗(yàn)。

默認(rèn)為 false

注意:

這個選項(xiàng)在 HTTP 和 FTP 協(xié)議中均可使用。

范例

示例 #1 獲取一個頁面,并以POST發(fā)送數(shù)據(jù)

<?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);

?>