CURL context options

CURL context optionsCURL 锟斤拷锟斤拷锟斤拷选锟斤拷锟叫憋拷

说锟斤拷

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

要锟斤拷锟绞癸拷玫锟絊SL证锟斤拷锟斤拷锟叫o拷椤�

默锟斤拷为 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);

?>