file_get_contents用流Post提交请求示例 收藏
2010年03月03日


记录一下,留着以后看方便。
这是一个post请求并的便子,主要在系统内部用。
外部请求可能要求登录信息,但基本上体现了file_get_contents的用法。


  1. function Post($url, $post = null)
  2. {
  3.     $context = array();
  4.     if (is_array($post)){
  5.         ksort($post);
  6.         $context['http'] = array(
  7.         'method' => 'POST',
  8.         'header'=>"Cookie:".$_SERVER['HTTP_COOKIE']."

    ",  //."

    "

  9.         'content' => http_build_query($post, '', '&'),
  10.         );
  11.         $s_stream=stream_context_create($context);
  12.        
  13.     }
  14.     return file_get_contents($url, false, $s_stream);
  15. }
  16.  
  17.  
  18. $url='http://localhost/090342/index.php?title=Property:Test_tom_1&action=submit';
  19.  
  20. $arr['wpTextbox1'] = 'This is a property of type [[Has type::String]].
  21.  
  22. The allowed values for this property are:
  23. * [[Allows value::a]]
  24. * [[Allows value::b]]
  25. * [[Allows value::c]]
  26. * [[Allows value::d]]
  27. * [[Allows value::f]]';
  28.  
  29. $arr['wpSummary']   = '';
  30.  $arr['wpStarttime'] = '';
  31.  $arr['wpEdittime']   ='';
  32.  $arr['wpEditToken'] = "210b3e0e4bb96c28d356d8892527d6dc+";
  33. $arr['wpSave'] ='';
  34.  
  35.  
  36. print_r($arr);
  37. //exit;
  38. $result=Post($url, $arr);
  39.  
  40. var_dump($result);

 

本文永久链接: http://www.zzxj.net/blog/fxs_2008/archive/2010/03/03/120.html

发表于 @ 2010年03月03日 |评论(loading... )|收藏

发表评论 姓  名: