Warning: curl_exec() has been disabled for security reasons in /pub/host/sunboyu/sunboyu/www/wp-includes/http.php on line 1022
file_get_contents函数使用post方法 » Blog Archive 一个程序猿 孙小一,孙小二,PHP,MYSQL,LINUX,APACHE,原创技术,扯淡

file_get_contents函数使用post方法

作者 : admin 于 2009-03-16 12:27:44
2009
03-16

以前总用socket的方式发送接收http的包,结果收到的包也有一堆http的协议头信息。
处理这些信息还挺费劲的。

然后想到了file_get_contents($url)方法,可以得到纯净的http包的正文。但这种方式默认是get的方式,后查手册和搜索,得到了post的方法。

这种方式基本跟socket的方式相同,包头构建好即可。

  1. $array = array ('a' => 'b','c'=>'d');
  2. $url= http_build_query($array );
  3. $postdate = array (
  4.     'http' => array (
  5.         'method' => 'POST',
  6.         'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
  7.                    "Content-Length: " . strlen($url) . "\r\n",
  8.         'content' => $url
  9.     ),
  10. );
  11. $postcontent = stream_context_create($postdate );
  12. $return= file_get_contents('http://www.sunboyu.cn', false, $postcontent ); 
  13. echo $return;

评论列表

  1. 三炮 Says:

    抓抓www.ip138.com试试看

发表评论




XHTML:你可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(若看不到验证码,请重新加载页面。)