php模拟post行为

简单的实现方式:

<?php
$params = "name=bob&age=12";
$fp = fsockopen("localhost", 80, $errno, $errstr, 30) 
    or die("Error: {$errstr}($errno)/r/n");
    
$out = "POST /test/fsockopen/post/post.php HTTP/1.1/r/n";
$out .= "Host: localhost/r/n";
$out .= "Content-Type: application/x-www-form-urlencoded/r/n";
$out .= "Content-length: " . strlen($params) . "/r/n";
$out .= "Connection: Close/r/n/r/n";
$out .= $params;
fwrite($fp, $out);
while (!feof($fp)) {
    echo fgets($fp, 1024);
}
?>

 

 

posted @ 2010-07-02 15:26  Iwillbback  阅读(73)  评论(0)    收藏  举报