Jump to content

Capturing POST response


acdx

Recommended Posts

[quote author=w32 link=topic=106634.msg426556#msg426556 date=1157211655]
Do it exactly as you'd have done it using the GET method, just use a form like this one:
<form action="your-script.php" method="post" enctype="application/x-www-form-urlencoded">

</form>
[/quote]

That's not what I want to do..

Let me explain.. I want to send a POST request that includes form data using php to a remote server/page and capture the response into a string.

This were easy if the script accepted GET form data (form data in the URL)

[code]<?php
$output = file_get_contents("http://a.com/script.php?a=this&b=that");
?>[/code]

How can I do this with POST?
I believe I can't do it with GET as the remote script only accepts POST.

I got things working with fsockopen() however. I tested this on my own server.

[code]<?php
$c = fsockopen([my hostname], 80);
$rq =
"POST /ptest.php HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 14

a=blah&b=blah2

";
fwrite($c, $rq);
while(!feof($c))
{
echo(htmlentities(fgets($c))."<br />");
}
?>[/code]

The receiving end in this test simply prints the variables:

[code]<?php
echo($_POST["a"]." and ".$_POST["b"]);
?>[/code]

As said, this is only a test where both files reside on my own server and the output is simply printed to the user.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.