file_get_contents函数使用post方法
作者 : admin 于 2009-03-16 12:27:44
2009
03-16
03-16
以前总用socket的方式发送接收http的包,结果收到的包也有一堆http的协议头信息。
处理这些信息还挺费劲的。
然后想到了file_get_contents($url)方法,可以得到纯净的http包的正文。但这种方式默认是get的方式,后查手册和搜索,得到了post的方法。
这种方式基本跟socket的方式相同,包头构建好即可。
- $array = array ('a' => 'b','c'=>'d');
- $url= http_build_query($array );
- $postdate = array (
- 'http' => array (
- 'method' => 'POST',
- 'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
- "Content-Length: " . strlen($url) . "\r\n",
- 'content' => $url
- ),
- );
- $postcontent = stream_context_create($postdate );
- $return= file_get_contents('http://www.sunboyu.cn', false, $postcontent );
- echo $return;
三月 27th, 2009 at 15:42:17
抓抓www.ip138.com试试看