最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP stream_context_create()作用和用法分析

 更新時間:2011年03月29日 16:32:15   作者:  
創(chuàng)建并返回一個文本數(shù)據(jù)流并應(yīng)用各種選項,可用于fopen(),file_get_contents()等過程的超時設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程。
作用:創(chuàng)建并返回一個文本數(shù)據(jù)流并應(yīng)用各種選項,可用于fopen(),file_get_contents()等過程的超時設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程。
函數(shù)原型:resource stream_context_create ([ array $options [, array $params ]] )
用法
例子一:
復(fù)制代碼 代碼如下:

<?php
$opts = array( 'http-->array(
'method'=&gt;"GET",
'header'=&gt;"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
/* Sends an http request to m.fzitv.net
with additional headers shown above */
$fp = fopen('http://m.fzitv.net', 'r', false, $context);
fpassthru($fp);
fclose($fp);
?>

例子二:
復(fù)制代碼 代碼如下:

<?php
$opts = array( 'http-->array(
'method'=&gt;"GET",
'header'=&gt;"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
?>
You would setup the header this way:
<?php
$opts = array( 'http-->array(
'method'=&gt;"GET",
'header'=&gt;array("Accept-language: en",
"Cookie: foo=bar",
"Custom-Header: value")
)
);
$context = stream_context_create($opts);
?>

例子三:
復(fù)制代碼 代碼如下:

<?php
$opts = array('http' => array('proxy' => 'tcp://127.0.0.1:8080', 'request_fulluri' => true));
$context = stream_context_create($opts);
$data = file_get_contents('http://m.fzitv.net', false, $context);
echo $data;
?>

例子四:
復(fù)制代碼 代碼如下:

<?php
function do_post_request($url, $postdata, $files = null)
{
$data = "";
$boundary = "---------------------".substr(md5(rand(0,32000)), 0, 10);
//Collect Postdata
foreach($postdata as $key => $val)
{
$data .= "--$boundary\n";
$data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n";
}
$data .= "--$boundary\n";
//Collect Filedata
foreach($files as $key => $file)
{
$fileContents = file_get_contents($file['tmp_name']);
$data .= "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file['name']}\"\n";
$data .= "Content-Type: image/jpeg\n";
$data .= "Content-Transfer-Encoding: binary\n\n";
$data .= $fileContents."\n";
$data .= "--$boundary--\n";
}
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: multipart/form-data; boundary='.$boundary,
'content' => $data
));
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
//set data (in this example from post)
//sample data
$postdata = array(
'name' => $_POST['name'],
'age' => $_POST['age'],
'sex' => $_POST['sex']
);
//sample image
$files['image'] = $_FILES['image'];
do_post_request("http://m.fzitv.net", $postdata, $files);
?>

相關(guān)文章

最新評論

平果县| 萨迦县| 台北市| 桦甸市| 分宜县| 神池县| 荆州市| 秭归县| 铁岭市| 辉县市| 香港 | 安泽县| 商丘市| 铜梁县| 娱乐| 鸡西市| 沾化县| 永川市| 蒙阴县| 安阳县| 呼伦贝尔市| 奈曼旗| 普安县| 信阳市| 陆河县| 布拖县| 奉节县| 渭南市| 从江县| 昆明市| 舒兰市| 崇阳县| 广宗县| 永城市| 临安市| 独山县| 吴川市| 手机| 阿拉善盟| 琼结县| 绥江县|