国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php stream_context_create函數

2024-09-04 11:48:57
字體:
來源:轉載
供稿:網友

stream_context_create創建并返回一個文本數據流并應用各種選項,可用于fopen(),file_get_contents()等過程的超時設置、代理服務器、請求方式、頭信息設置的特殊過程.

函數原型:resource stream_context_create ([array $options [,array $params ]] ),看個實例:

  1. //定義options數組 
  2. $opts=array 
  3.   'http'=>array 
  4.   ( 
  5.     'method'=>"get"
  6.     'header'=>"accept-language: enrn"."cookie: foo=barrn" 
  7.   ) 
  8. ); 
  9. //創建數據流上下文 
  10. $context=stream_context_create($opts); 
  11. /*向指定地址發送http請求 
  12. 請求中包含附加的頭部信息*/ 
  13. $fp=fopen('http://www.111cn.net','r',false,$context); 
  14. //輸出文件指針處的所有數據 
  15. fpassthru($fp); 
  16. //關閉文件 
  17. fclose($fp); 
  18. /* 
  19. //該代碼的輸出結果為:即請求的cookie值 
  20. array 
  21. ( 
  22.     [foo] => bar 
  23. ) 
  24. */ 

實例二,代碼如下:

  1. $default_opts=array 
  2.   'http'=>array 
  3.   ( 
  4.     'method'=>"get"
  5.     'header'=>"accept-language: enrn"."cookie: foo=bar"
  6.     'proxy'=>"tcp://10.54.1.39:8000" 
  7.   ) 
  8. ); 
  9. $alternate_opts=array 
  10.   'http'=>array 
  11.   ( 
  12.     'method'=>"post"
  13.     'header'=>"content-type: application/x-www-form-urlencodedrn"."content-length: " . strlen("baz=bomb"), 
  14.     'content'=>"baz=bomb" 
  15.   ) 
  16. ); 
  17. $default=stream_context_get_default($default_opts); 
  18. $alternate=stream_context_create($alternate_opts); 
  19. /* sends a regular get request to proxy server at 10.54.1.39 
  20. * for www.survivalescaperooms.com using context options specified in $default_opts 
  21. */ 
  22. readfile('http://www.survivalescaperooms.com'); 
  23. /* sends a post request directly to www.survivalescaperooms.com 
  24. * using context options specified in $alternate_opts 
  25. */ 
  26. readfile('http://www.survivalescaperooms.com', false, $alternate);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 韩城市| 抚松县| 哈巴河县| 衢州市| 定安县| 株洲县| 赫章县| 巴林右旗| 常德市| 桦甸市| 双城市| 方正县| 昌江| 盐源县| 荆州市| 涿州市| 石林| 兰溪市| 新乐市| 通江县| 西丰县| 汤阴县| 澄迈县| 汉源县| 库尔勒市| 周宁县| 青川县| 安多县| 永胜县| 富源县| 郁南县| 毕节市| 内江市| 大丰市| 栾城县| 连江县| 正阳县| 方城县| 武夷山市| 塔河县| 阜阳市|