Re: Simulating POST
| From: | David Duong | Date: | Sat, 14 Sep 2002 16:00:36 +0000 |
| Subject: | Re: Simulating POST | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116379@lists.php.net to get a copy of this message | ||
Thnx for all your help.
"Paul Nicholson" <paul@dtnicholson.com> wrote in message
news:200209140050.g8E0og625775@DTN01.network.webpowerdesign.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hey,
> Try this:
> - -- php code --
> $data ="insert=data&location=here"; /* This would be the data that needs
to
> be posted to the site - urlencode it */
> /* Headers for http transaction....replace /folder/pages.ext */
> $header = "POST /folder/pages.ext HTTP/1.1\r\n".
> "Accept-Language: en-us\r\n". /* Additional info for the
> receiving server.....optional */
> "Content-Length: ".strlen($data)."\r\n". /* This line is
> *very* important - length of posted data */
> "Content-Type: application/x-www-form-urlencoded\r\n". /*
Type
> of content the server can expect from us */
> "User-Agent: YourCustomUser-Agent (compatible; Linux 2.4;
> RedHat 7.2;)\r\n". /* optional */
> "Host: host.com\r\n". /* the "host" of the site you are
> sending the posted data to.....*/
> "Cookie: cookie-name=cookie-val\r\n\r\n". /* We can even
send
> cookies!!!! optional......remove and add an extra \r\n to the above line
*/
> "$data"; /* this is where the data is sent....no need to
> change this line. */
> $fp = fsockopen ("host.com", 80, $errno, $errstr, 30);
> if (!$fp) {
> echo "$errstr ($errno)<br>\n";
> } else {
> fputs ($fp, $header);
> while (!feof($fp)) {
> echo fgets ($fp,128); /* Data returned from server.....use as you
> like */
> }
> fclose ($fp);
> }
> - -- End php code --
> Let me know how it works:)
> ~Pauly
>
> On Friday 13 September 2002 08:08 pm, you wrote:
> > How can I simulate a POST (from HTML forms) request?
>
> - --
> ~Paul Nicholson
> Design Specialist @ WebPower Design
> "The web....the way you want it!"
> paul@webpowerdesign.net
>
> "It said uses Windows 98 or better, so I loaded Linux!"
> Registered Linux User #183202 using Register Linux System # 81891
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
>
> iD8DBQE9goTyDyXNIUN3+UQRAlThAJsE2NPk3PjLRlY11wDaJ1SV/kaidQCfW2Oi
> r4r8y9mIc4eC+/crurQ4EFs=
> =bfs+
> -----END PGP SIGNATURE-----