Responding To HTTP Post

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

    Responding To HTTP Post

    I am trying to figure out how to respond to an HTTP post in php script.
    Can anyone help?

  • Sean

    #2
    Re: Responding To HTTP Post

    Only you can answer how you plan to code the response, but if you do
    get http post you can access it like:

    $var1 = $_POST['var1'];

    or to start off use:

    print_r ($_POST); //which will show all the data posted to the script.

    Comment

    • Zack

      #3
      Re: Responding To HTTP Post

      My question deals with establishing a connection. It appears that
      establishing a new connection using fsockopen() would not connect me to
      the originator's session and I don't know how to re-use the existing
      connection.

      Comment

      • Zack

        #4
        Re: Responding To HTTP Post

        My question deals with establishing a connection. It appears that
        establishing a new connection using fsockopen() would not connect me to
        the originator's session and I don't know how to re-use the existing
        connection.

        Comment

        • Sean

          #5
          Re: Responding To HTTP Post

          OK, use http://php.net/curl

          Comment

          • Zack

            #6
            Re: Responding To HTTP Post

            I was not able to find the answer to my question in the CURL
            documentation. I understand that it may not be possible to do this
            using php.

            My script would get a request via POST from a client. The client would
            wait for response. In order for me to respond, I need to get a handle
            to the initial connection. This may not be possible. I think that this
            type of situations are usually handled via a coordinating daemon.

            Comment

            • Gordon Burditt

              #7
              Re: Responding To HTTP Post

              >I was not able to find the answer to my question in the CURL[color=blue]
              >documentatio n. I understand that it may not be possible to do this
              >using php.
              >
              >My script would get a request via POST from a client. The client would
              >wait for response. In order for me to respond, I need to get a handle
              >to the initial connection.[/color]

              If your page is running under PHP, you already have a connection.
              Output something (say, with echo or header() or something).
              [color=blue]
              >This may not be possible. I think that this
              >type of situations are usually handled via a coordinating daemon.[/color]

              If you are making an outgoing connection to something (with, say,
              fopen on a remote URL) and want to copy the response IT sends to
              the request you got, look at fpassthru().

              Otherwise, I don't understand your problem.

              Gordon L. Burditt

              Comment

              • Zack

                #8
                Re: Responding To HTTP Post

                My question is not well stated. Let me try again.

                I am working on a php script that will receive database requests from
                remote URL's. The script's job is to execute the request and send the
                results back to the requester.

                The requester does the following:

                1. Open a connection using fsockopen().
                2. Post headers and request using fputs()
                3. Read response using fgets()

                This works fine. I am using a class that does that in other
                applications communicating with applications that successfully send the
                responses back. I am trying to write a script that also sends responses
                back and that is where I am running into difficulties

                The problem script obtains the request from $_POST. That also works.
                The question is how do I send the response back to requester so that it
                can read it using fgets(). Or, more specifically, how do I establish a
                connection back to the requester so that I can send the response.

                If I use fsockopen() to establish a connection to the requesting URL,
                it appears that it would not be communicating with the same session. I
                also don't see a way to get a handle to the existing connection that
                was created by the requester.

                Comment

                • Gordon Burditt

                  #9
                  Re: Responding To HTTP Post

                  >My question is not well stated. Let me try again.[color=blue]
                  >
                  >I am working on a php script that will receive database requests from
                  >remote URL's. The script's job is to execute the request and send the
                  >results back to the requester.
                  >
                  >The requester does the following:
                  >
                  >1. Open a connection using fsockopen().
                  >2. Post headers and request using fputs()
                  >3. Read response using fgets()[/color]

                  Forget these details. Pretend the situation is: Someone typed the
                  URL into a browser or clicked on a link. Then do what is appropriate:
                  output something. Ok, you're outputting xml instead of html. Big
                  deal. Text is text. When you get a request, it's difficult to
                  tell that it's *NOT* someone with a browser, and you shouldn't try
                  to distinguish the difference anyway.
                  [color=blue]
                  >This works fine. I am using a class that does that in other
                  >applications communicating with applications that successfully send the
                  >responses back. I am trying to write a script that also sends responses
                  >back and that is where I am running into difficulties
                  >
                  >The problem script obtains the request from $_POST. That also works.
                  >The question is how do I send the response back to requester so that it
                  >can read it using fgets().[/color]

                  Don't even think about trying to establish a connection, the other
                  end already did it. OUTPUT SOMETHING!! echo. print. printf.
                  fpassthru. (Maybe you want a header("Content-type: text/xml")
                  first).

                  echo "<xml>respo nse</xml>\n";

                  Note the complete absence of any reference to functions with the
                  substring "open" or "sock" and the complete absence of handles.
                  [color=blue]
                  >Or, more specifically, how do I establish a
                  >connection back to the requester so that I can send the response.[/color]

                  When you receive a telephone call, answer it, and the caller asks
                  a question, do you need to call him back to send answer? No, you
                  just *TALK*. It doesn't matter whether the caller is using a VOIP
                  switch or an old mechanical switchboard and asked the operator to
                  make the call for him. It doesn't matter whether the call goes
                  via a satellite. You just talk.
                  [color=blue]
                  >If I use fsockopen() to establish a connection to the requesting URL,[/color]

                  Do not establish a connection. You've got one established by the
                  other end. USE IT!
                  [color=blue]
                  >it appears that it would not be communicating with the same session. I
                  >also don't see a way to get a handle to the existing connection that
                  >was created by the requester.[/color]

                  You don't need a handle. OUTPUT SOMETHING!!!


                  Gordon L. Burditt

                  Comment

                  • Zack

                    #10
                    Re: Responding To HTTP Post

                    Got it! Thanks. Now I just need to find an optimal way to deal with
                    chunked encoding.

                    Comment

                    • Manuel Lemos

                      #11
                      Re: Responding To HTTP Post

                      Hello,

                      on 11/27/2005 03:59 PM Zack said the following:[color=blue]
                      > My question deals with establishing a connection. It appears that
                      > establishing a new connection using fsockopen() would not connect me to
                      > the originator's session and I don't know how to re-use the existing
                      > connection.[/color]

                      You may want to try this HTTP Client class that can submit post
                      requests, collect and send back cookies (of your sessions) and most of
                      other operations to make it act like a real browser:




                      --

                      Regards,
                      Manuel Lemos

                      Metastorage - Data object relational mapping layer generator
                      ✅「官方网站」mk体育拥有各种免费又安全的资源,因为亚洲当中中国玩家人口基数的众多,mk体育创造了中国网络游戏的神话,全球首推免费在线点播体育直播。


                      PHP Classes - Free ready to use OOP components written in PHP

                      Comment

                      Working...