Re: Re: Sending post data from a script

From: Date: Sat, 06 Aug 2005 09:34:28 +0000
Subject: Re: Re: Sending post data from a script
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-220137@lists.php.net to get a copy of this message
you can try this: $sock = fsockopen($parse_url['host'], $parse_url['port'], $errno, $errstr, 30); if (!$sock) { die("$errstr ($errno)\r\n"); } $tmp = explode('&',$parse_url['query']); $data = NULL; foreach($tmp as $val) { $p = explode('=',$val); if(empty($data)) { $data = $p[0] . "=" . urlencode($p[1]); } else { $data .= "&" . $p[0] . "=" . urlencode($p[1]); } } fwrite($sock, "POST " . $parse_url['path'] . " HTTP/1.0\r\n"); fwrite($sock, "Host: " . $parse_url['host'] . "\r\n"); fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n"); fwrite($sock, "Content-length: " . strlen($data) . "\r\n"); fwrite($sock, "Accept: */*\r\n"); fwrite($sock, "\r\n"); fwrite($sock, "$data\r\n"); fwrite($sock, "\r\n"); $body = ""; while (!feof($sock)) { $body .= fgets($sock, 4096); } fclose($sock);

« previous php.general (#220137) next »