Forum Moderators: coopster

Message Too Old, No Replies

send response to a post

         

Sunny_Dee

4:52 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



Hi,

If my server receives a POST, how can I send a custom POST back indicating I received the initial POST ok and I'd like to send something back in the POST body.

Thanks!

Sunny_Dee

5:35 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



This is what I have so far, but doesn't seem to be able to connect to the server that is sending the POST to me...

<?php
$host = gethostbyname($_SERVER['REMOTE_ADDR']);
$myPIN = $_POST['PIN'];

$key = "key=" . $myPIN;

$fp = fsockopen($host, 80);

fputs($fp, "HTTP/1.1 200 Ok\r\n");
fputs($fp,"Content-Type: application/www-url-encoded\r\n");
fputs($fp, "Content-Length: " . strlen($key) . "\r\n\r\n");
fputs($fp, $key);

fclose($fp);

?>

blang

6:49 pm on Mar 19, 2009 (gmt 0)

10+ Year Member



Huh? What are you trying to do? Please explain the context of the situation.

eeek

5:04 am on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If my server receives a POST, how can I send a custom POST back

You cannot. POST is a request from the client. The server sends a response to the POST request.

$fp = fsockopen($host, 80);

What makes you think the client is listening on port 80?

blang

7:30 am on Mar 21, 2009 (gmt 0)

10+ Year Member



You cannot. POST is a request from the client. The server sends a response to the POST request.

That's not exactly accurate. Take a look at the cURL extension. I think that's what is needed here if we could just get some more details as to what the OP is attempting to achieve.

I once built a lousy interface using a POST method form, that it became apparent should have been built with a few simple GETs and made more user-friendly with some rewrite rules. Anyway, what I wound up doing instead of rewriting the entire application was creating a script that uses cURL to make those POST requests in response to a regular link.