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?
Link to comment
Share on other sites

[quote author=w32 link=topic=106634.msg426595#msg426595 date=1157213849]
yip :)

you'll still need a form if using POST, lol ;)
[/quote]
In my scenario, it's not the user that POSTs the data and looks at the response, it's my PHP script that does..
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.