How to return data using POST

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Quiring

    #1

    How to return data using POST

    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'=>"Cont ent-type: application/x-www-form-urlencoded\r\n" .
    "Content-length: " . strlen("$LINKOU T"),
    'content'=>"$LI NKOUT"
    )
    );
    $context = stream_context_ create($LOUT);

    Thanks
    Gary Quiring

  • Colin McKinnon

    #2
    Re: How to return data using POST

    Gary Quiring wrote:
    [color=blue]
    > 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?
    >[/color]

    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.

    Comment

    • Alvaro G Vicario

      #3
      Re: How to return data using POST

      *** Gary Quiring wrote/escribió (Thu, 12 May 2005 10:20:29 -0400):[color=blue]
      > 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?[/color]

      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
      --

      Comment

      • Daniel Tryba

        #4
        Re: How to return data using POST

        Gary Quiring <gquiring@msn.c om> wrote:[color=blue]
        > 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?[/color]

        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).

        Comment

        • Gary Quiring

          #5
          Re: How to return data using POST

          On Thu, 12 May 2005 16:05:19 +0100, Colin McKinnon
          <colin.deleteth is@andthis.mms3 .com> wrote:
          [color=blue]
          >Gary Quiring wrote:
          >[color=green]
          >> 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?
          >>[/color]
          >
          >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.[/color]
          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

          Comment

          • Ken Robinson

            #6
            Re: How to return data using POST


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

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

            Ken

            Comment

            Working...