By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,233 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

How to return data using POST

P: n/a
I have a vendor sending me a text file using POST. I have a PHP program
receiving the data that works. I need to in the same stream return an answer
via POST. How do I send that POST in the same stream?

A snip from the code for the output portion:

$LINKOUT = implode('', file($LINKFILE . '.out'));

$LOUT = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length: " . strlen("$LINKOUT"),
'content'=>"$LINKOUT"
)
);
$context = stream_context_create($LOUT);

Thanks
Gary Quiring

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Gary Quiring wrote:
I have a vendor sending me a text file using POST. I have a PHP program
receiving the data that works. I need to in the same stream return an
answer
via POST. How do I send that POST in the same stream?


You seem to be describing something which isn't HTTP - in HTTP, the client
opens a socket to the designated port (default 80) on the server, sends a
request which is usually POST or GET (but can be other things to). The
server responds with some response headers and optionally some content. If
you want to initiate a POST from the server then it must initiate a new
connection _as_ a client.

If you merely want to make some response to the POST....just output
something to the browser:
print (count($_POST) ? "Thanks,...got it\n" : "eh ? Nothing sent\n");

POST and GET are semantically and functionally different in HTTP but, apart
from the fact they are stored in seperate variables, are no different from
the point of view of PHP (except when uploading files - because HTTP only
allows that via POST).

HTH

C.

Jul 17 '05 #2

P: n/a
*** Gary Quiring wrote/escribió (Thu, 12 May 2005 10:20:29 -0400):
I have a vendor sending me a text file using POST. I have a PHP program
receiving the data that works. I need to in the same stream return an answer
via POST. How do I send that POST in the same stream?


As far as I know it's impossible. HTTP is a stateless protocol that has
client-server design. If your vendor's HTTP client contacts your HTTP
server, you cannot use that same connection to invert roles an make your
server act as client and viceversa.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3

P: n/a
Gary Quiring <gq******@msn.com> wrote:
I have a vendor sending me a text file using POST. I have a PHP program
receiving the data that works. I need to in the same stream return an answer
via POST. How do I send that POST in the same stream?


You can't, this is simply not how http works.

The client opens a connection, sends headers (in your case a POST) and
data (the file). When it's finished sending you can send back anything
you like using normal output functions like echo/print/whatever (in your
case the header and content from the http hash). And then close the
connection (or accept another request if keep-alive is enabled).

Jul 17 '05 #4

P: n/a
On Thu, 12 May 2005 16:05:19 +0100, Colin McKinnon
<co**************@andthis.mms3.com> wrote:
Gary Quiring wrote:
I have a vendor sending me a text file using POST. I have a PHP program
receiving the data that works. I need to in the same stream return an
answer
via POST. How do I send that POST in the same stream?


You seem to be describing something which isn't HTTP - in HTTP, the client
opens a socket to the designated port (default 80) on the server, sends a
request which is usually POST or GET (but can be other things to). The
server responds with some response headers and optionally some content. If
you want to initiate a POST from the server then it must initiate a new
connection _as_ a client.

If you merely want to make some response to the POST....just output
something to the browser:
print (count($_POST) ? "Thanks,...got it\n" : "eh ? Nothing sent\n");

POST and GET are semantically and functionally different in HTTP but, apart
from the fact they are stored in seperate variables, are no different from
the point of view of PHP (except when uploading files - because HTTP only
allows that via POST).

HTH

C.

Ok I was not sure what to do. They do not have a spec and I have never done any
HTML or PHP before. It's all new stuff to me. In the past everyone was happy
sending via FTP and for some reason there is a 'rush' of new 3rd party software
houses that refuse to use anything but http to send some data.

Gary

Jul 17 '05 #5

P: n/a

Gary Quiring wrote:
I have a vendor sending me a text file using POST. I have a PHP program receiving the data that works. I need to in the same stream return an answer via POST. How do I send that POST in the same stream?


Go to www.php.net/curl and look at the second comment. That should
answer your question.

Ken

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.