9 Replies Latest reply on Jan 12, 2007 4:54 AM by Sargon42

    Catching HTTP content under CF5

    Sargon42
      Hello

      I'm running ColdFusion 5 (yes, I know it's quite outdated...) under Solaris and try to catch posted data in the CF-page for further processing. According to the documentation, GetHttpRequestData() looks like what would do the job.

      Here's the sample code:

      [code]
      <cfoutput><pre>
      BEGIN
      <cfset request = GetHttpRequestData()>
      #request.content#
      END
      </pre></cfoutput>
      [/code]


      Now I send the following request to CF:

      [request]
      telnet myhost.example.com 80
      POST /SOAP/Soap.cfm HTTP/1.1
      Host: myhost.example.com
      Content-Type: application/soap+xml
      Content-Length: 15

      aaa
      bbb
      ccc

      [/request]


      The variable "request.content" seems to be completely empty though. What am I missing? Isn't it possible to simply catch the raw content of a POST in CF5?

      Kind regards,
      Daniel
        • 1. Re: Catching HTTP content under CF5
          Sargon42 Level 1
          Hi

          Is there _anyone_ who can say anything to this, please? :) A "it works for me" would help too. :)

          I've found several messages on the Internet from from people who experience the same problem:

          http://www.houseoffusion.com/groups/CF-Talk/thread.cfm/threadid:24200
          http://www.houseoffusion.com/groups/CF-Talk/thread.cfm/threadid:18584
          http://www.cs.miami.edu/students/strac/svg/files/arrows.html

          Comments? Ideas? Shrieking epitaphs?

          Kind regards
          Daniel
          • 2. Re: Catching HTTP content under CF5
            Level 7
            hmmm...I use it on a windows server with cf 5 and I'm pretty sure it
            works (don't have access to that server anymore), don't know about
            Solaris. Maybe it's something to do with the name of your variable?
            "request" is used by CF as a scope. try renaming your variable?
            HTH
            --
            Tim Carley
            www.recfusion.com
            info@NOSPAMINGrecfusion.com
            • 3. Re: Catching HTTP content under CF5
              Sargon42 Level 1
              Hello

              Thanks for your answer! The renaming didn't help but my quoted example was not really the one I've tried. ;)

              When changing the content-type to "text/xml", everything works fine. The documentation says that if the content-type is neither "text/..." nor "application/x-www-form-urlencoded", the content itself will be stored as a binary object. This binary object seems to be empty though. When writing it to a file, the file is empty. When checking with the isBinary() function, CF5 tells me it's not binary object. And finally converting it with toString() also doesn't help. (it stays empty)

              Any pointers what else I could try?

              Many thanks in advance! :)
              Daniel
              • 4. Re: Catching HTTP content under CF5
                SpiderFromMars Level 1
                The 'content' of getHTTPrequestData() return, in either string or binary format, the form data that was submitted by the client. It does not return the page content. (At least this is how it works in 6.1).

                Your 'content' is empty because you are not passing any form data.

                If you want to interrogate the page data... try using CFSAVECONTENT and interrogate the variable to get what you need ;)

                Hope this helps :)
                Peter
                • 5. Re: Catching HTTP content under CF5
                  Sargon42 Level 1
                  Hallo SpiderFromMars :)

                  But I _want_ all the data the client was sending. The documentation of GetHttpRequestData() says "Makes HTTP request headers and body available to CFML pages.", which is exactly what I want. It goes on by saying this is expecially useful for capturing SOAP requests - which again is exactly what I want.

                  The tag CFSAVECONTENT on the other hand seems to be good for 'capturing' the server-side generated response in a CF-variable before actually sending it to the client.

                  So I'm kinda confident that GetHttpRequestData() is what I want here. Either that or I misunderstood you and/or the CF5 documentation. :)

                  Kind regards
                  Daniel
                  • 6. Re: Catching HTTP content under CF5
                    SpiderFromMars Level 1
                    Hi Daniel:

                    How are you receiving the data from the client? Are you using CFHTTP? If so, use the cfhttp.filecontent variable. If you are using another method, let me know and I'll help you find something else.

                    The LiveDocs do indeed state that the body of the message is displayed, but <all_hail>Ben Forta's</all_hail> Web Application Construction Kit states that the content only contains form data. I ran a few tests and this is indeed the case. Forta: right. Livedocs: not-so-right :->

                    Cheers,
                    Peter




                    Hallo SpiderFromMars :)

                    But I _want_ all the data the client was sending. The documentation of GetHttpRequestData() says "Makes HTTP request headers and body available to CFML pages.", which is exactly what I want. It goes on by saying this is expecially useful for capturing SOAP requests - which again is exactly what I want.

                    The tag CFSAVECONTENT on the other hand seems to be good for 'capturing' the server-side generated response in a CF-variable before actually sending it to the client.

                    So I'm kinda confident that GetHttpRequestData() is what I want here. Either that or I misunderstood you and/or the CF5 documentation. :)

                    Kind regards
                    Daniel
                    • 7. Re: Catching HTTP content under CF5
                      Sargon42 Level 1
                      Hi Peter

                      No, I'm not doing cfhttp. In my case, the client sends a SOAP message to a ColdFusion page and I'm trying to access this SOAP message in the CF-page to process it further.

                      The client sends something like this:

                      POST /SOAP/Soap.cfm HTTP/1.1
                      Host: myhost.example.com
                      Content-Type: application/soap+xml
                      Content-Length: nnnn

                      <SOAP-ENV:Envelope>
                      ....
                      </SOAP-ENV:Envelope>


                      In CF I would like to get access to the XML-document "<SOAP-ENV:Envelope>" in the body.

                      If the client uses "text/xml" as content-type, I can access the XML-document with GetHttpRequestData().content. If the content-type is "application/soap+xml" though, GetHttpRequestData().content is simply empty. According to the CF documentation it should be a binary object though.

                      I will ask the customer, whether she can send "text/xml" as content-type instead, but as you know customers, that prolly won't work :)

                      If I could use Apache2, I could change the content-type on the server side with the mod_headers module, but since the CF5-module is not available/supported under Apache2, that's also a no-go. :(

                      Any hints would be greatly appreciated. :)

                      Kind regards
                      Daniel
                      • 8. Re: Catching HTTP content under CF5
                        SpiderFromMars Level 1
                        Hi Daniel:

                        This is quite interesting and leaves me a bit stumped.

                        The easiest (but most expensive) way woudl be to update to CFMX 7.0 and then write a web service to consume this package.

                        You also might want to check: http://www.activsoftware.com/xml/

                        There are some useful XML tools there that will work with 5.0. The SOAP tool they have there, though, appears only to send requests and not process incoming ones.

                        Please keep me posted on this! I'd like to know the solution.

                        Peter
                        • 9. Re: Catching HTTP content under CF5
                          Sargon42 Level 1
                          Hey Peter

                          Upgrading to CF7 is even more unthinkable than upgrading just Apache. :) So I think I'll try to convince our customer instead. If I stumble over another solution, I'll post it. :)

                          Thanks!

                          Daniel