Don't say much nonsense. Directly on the code:
sock_post.php:
Copy CodeThe code is as follows:
function Sock_post ($url, $data = ") {
$url = Parse_url ($url);
$url [' scheme '] | | $url [' scheme '] = ' http ';
$url [' Host '] | | $url [' host '] = $_server[' http_host '];
$url [' path '][0]! = '/' && $url [' path '] = '/'. $url [' Path '];
$query = $data;
if (Is_array ($data)) $query = Http_build_query ($data);
$fp = @fsockopen ($url [' Host '], $url [' Port ']? $url [' Port ']: 80);
if (! $fp) return "Failed to open socket to $url [host]";
Fputs ($FP, sprintf ("POST%s%s%s http/1.0/n", $url [' Path '], $url [' query ']? "?": "", $url [' query ']);
Fputs ($FP, "Host: $url [host]/n");
Fputs ($fp, "content-type:application/x-www-form-urlencoded/n");
Fputs ($FP, "Content-length:".) Strlen ($query). "/n");
Fputs ($fp, "connection:close/n/n");
Fputs ($FP, "$query/n");
$line = fgets ($fp, 1024);
if (@!eregi ("^http/1/. ", $line)) return;
$results = "";
$inheader = 1;
while (!feof ($fp)) {
$line = fgets ($fp, 1024);
if ($inheader && ($line = = "/n" | | $line = = "/r/n")) {
$inheader = 0;
}elseif (! $inheader) {
$results. = $line;
}
}
Fclose ($FP);
return $results;
}
$re = Sock_post (' http://localhost/direct_post/get_post.php?id=1 ', Array (' wel ' = ' hello '));
Echo $re;
?>
get_post.php:
Copy the Code code as follows:
echo "Post:";
Print_r ($_post);
Echo ' Get: ';
Print_r ($_get);
?>
http://www.bkjia.com/PHPjc/328127.html www.bkjia.com true http://www.bkjia.com/PHPjc/328127.html techarticle don't say much nonsense. Directly on the code: sock_post.php: Copy code code as follows: Php function Sock_post ($url, $data = ") {$url = Parse_url ($url); $url [' scheme '] | | $url [ ' Scheme ' = ...