You are here: Re: how does one send a large string as a POST to another web page? « PHP Programming Language « IT news, forums, messages
Re: how does one send a large string as a POST to another web page?

Posted by NC on 11/06/41 11:44

lawrence k wrote:
>
> If I've a big string and I want to send it to another web page as a
> GET request, I just use file(). I've done this often.
>
> But what command do I use when I want to send the same string
> as a POST request?

You just send a POST request:

$content = '';
$flag = false;
$post_query = 'a=1&b=2'; // name-value pairs
$post_query = urlencode($post_query) . "\r\n";
$host = 'www.somehost.com';
$path = 'path/to/some/script.php';
$fp = fsockopen($host, '80');
if ($fp) {
fputs($fp, "POST $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-length: ". strlen($post_query) ."\r\n\r\n");
fputs($fp, $post_query);
while (!feof($fp)) {
$line = fgets($fp, 10240);
if ($flag) {
$content .= $line;
} else {
$headers .= $line;
if (strlen(trim($line)) == 0) {
$flag = true;
}
}
}
fclose($fp);
}

Now $headers contains HTTP headers returned by the remote server, while
$content contains the body of the response (the document you are trying
to retrieve).

Cheers,
NC

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация