Re: send a POST to a URL from within PHP code
| From: | Daniel Pupius | Date: | Mon, 26 Jan 2004 14:24:47 +0000 |
| Subject: | Re: send a POST to a URL from within PHP code | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-175758@lists.php.net to get a copy of this message | ||
You need to open a socket:
http://uk.php.net/manual/en/function.fsockopen.php
Think there's a demo in the comments lower down the page.
Yup, here it is:
function httpPost($host, $path, $referer, $data) {
$fp = fsockopen($host, 80);
fputs($fp, "POST ".$path." HTTP/1.0\r\n");
fputs($fp, "Host: ".$host."\r\n");
fputs($fh, "Referer: ".$referer."\r\n");
fputs($fp, "Content-type: application/x-www-url-encoded\r\n");
fputs($fp, "Content-length: ".strlen($data)."\r\n");
fputs($fp, "\r\n");
fputs($fp, $data."\r\n");
fputs($fp, "\r\n");
$tmp_headers = "";
while ($str = trim(fgets($fp, 4096)))
$tmp_headers .= $str."\n";
$tmp_body = "";
while (!feof($fp))
$tmp_body .= fgets($fp, 4096);
fclose($fp);
return $tmp_body;
}
"Vincent Dupont" <Vincent.dupont@ausy.be> wrote in message
news:B25AE43B1720D711A8B300508BEF38BB0BDF23@osexc.ausy.be...
Hi all,
I would like to simulate sending a form in POST to a specified URL through
PHP. I knwo how to do this from a HTML form :
<form method="post" action="http://url.com/query">
blablabla
</form>
I would just like to simulate this because I have some processes that will
change the values of the form before sending it to the 'action' URL
With a GET, the fields would be included into the query strinbg, so this is
quite easy. What happens in a POST?
Any idea is welcome
Vincent
mailto: vincent.dupont@ausy.be