16 Replies Latest reply on Jan 19, 2010 4:19 PM by Adam Cameron.

    CFHTTP problem with Host Headers

    doncx Level 1

      I am trying to post a form on a windows server using cfhttp.

       

      The website relies on host headers to work properly (there are many sites on the server), but cfhttp posts appear not to send the required header information, returning a "No websites are configured" error message.

       

      I've tried sending header info with <cfhttpparam type="header" name="host" value="www.mydomain.tld"> and it hasn't worked.

       

      It may be important to know that the domain name is local only and relies on an entry in the hosts file, both on the browser machine and the server machine.

       

      I have recently reconfigured the web server.  Previously, each site had its own IP address, but now they are all the same and using host headers.  Before, when each site had a unique IP, the cfhttp posts worked fine.

       

      Is there a way to get them working in the host header configuration?

       

      Thanks for replies.

       

      - Don

        • 1. Re: CFHTTP problem with Host Headers
          Adam Cameron. Level 5

          But hang on... host headers are a web server conceit, are they not?  The client agent (ie: <cfhttp> in this case) just sends an HTTP request to a domain name.  It's up to the web server to untangle which domain name goes to which website within its config.  All <cfhttp> needs to send is an HTTP to request to a valid domain, just like if I was typing in a URL in my web browser... the web browser doesn't need anything other than the domain name to reach the web server (assuming the domain name can be resolved into an IP address and get routed correctly, obviously).

           

          ?

           

          --

          Adam

          • 2. Re: CFHTTP problem with Host Headers
            BKBK Adobe Community Professional & MVP
            I've tried sending header info with <cfhttpparam type="header" name="host" value="www.mydomain.tld"> and it hasn't worked.

            Does this fare any better?

            <cfhttpparam type="header" name="host" value="mydomain.tld">

            • 3. Re: CFHTTP problem with Host Headers
              doncxe

              Thanks for the reply.  Unfortunately, it doesn't seem to make any difference.

               

              Any other ideas?

              • 4. Re: CFHTTP problem with Host Headers
                BKBK Adobe Community Professional & MVP

                Does IP address work as the value?

                • 5. Re: CFHTTP problem with Host Headers
                  doncxe Level 1

                  Not sure if I understand why this might work.

                   

                  Isn't the point of host headers to differentiate between multiple websites sharing a single IP?

                  • 6. Re: CFHTTP problem with Host Headers
                    BKBK Adobe Community Professional & MVP
                    Not sure if I understand why this might work.
                    Isn't the point of host headers to differentiate between multiple websites sharing a single IP?

                    It is. This is just for elimination.

                    • 7. Re: CFHTTP problem with Host Headers
                      doncxe Level 1

                      Consider it eliminated!

                       

                      The error changed though.  Instead of receiving a "no website configured" string from the CFHTTP call, I now get a ColdFusion error; "File Not Found" for the form at the target URL. (/forms/includes/form1.cfm).

                       

                      This makes sense, as the IP address points to the default webroot (c:\inetpub\wwwroot) and not the site referenced by the host header (c:\websites\mysite).

                       

                      Using host headers has saved time and IP configuration, and worked well for everything EXCEPT cfhttp calls.

                       

                      Any more ideas?

                      • 8. Re: CFHTTP problem with Host Headers
                        BKBK Adobe Community Professional & MVP

                        That got me thinking. Since you're local, have you registered the IP address and domain name in the /etc/hosts file?

                        • 9. Re: CFHTTP problem with Host Headers
                          doncx Level 1

                          Yes, absolutely.  The hosts file is accurate and identical on both the workstation and (more importantly, in this case) the server.

                           

                          I think that is an indicator of the problem:  Whatever web server is responding to the CFHTTP request doesn't seem to consult the hosts file.  I've presumed that is IIS (IIS-5 on Win2k) but perhaps not.

                           

                          The reason I say "perhaps not" is that IIS does in fact successfully consult the hosts file for HTTP requests that come from the workstation or its server console.  Why wouldn't it check the hosts file when responding to CFHTTP?  I have another server running IIS-6 and will give it a try also.

                           

                          So far, I can't seem to find the magic.

                          • 10. Re: CFHTTP problem with Host Headers
                            Adam Cameron. Level 5

                            The hosts file is used by the machine initiating TCP/IP communications to resolve an IP address from a domain name.  It's not used by the server to resolve a domain name from incoming HTTP requests (how could it: many domain names could map to the same IP address?).  The hosts file is a TCP/IP conceit; host headers are an HTTP conceit.  They are only loosely related in that HTTP is transported over TCP/IP.

                             

                            On your client some agent makes a request to a domain name (this can be any TCP/IP protocol, not just HTTP).  The hosts file is checked to see if the domain name has a mapping, and if it does, the request is routed to that IP address.  If there's no entry, then the standard DNS look-ups are made, and the IP address is found that way.  But that's the only involvement in the request (or any sort of routed traffic) that the hosts file has.

                             

                            Can you replicate this behaviour with <cfhttp> requests and other web servers, or is it just that one?  IE: can you set up a web server in the lab which has the same web site / host header config, and see the same problem when making <cfhttp> requests?  Does the web server log failed requests like this?  Usually IIS's logs are website-centric aren't they?  And if the request is not making to a web site, is it logged some other way?

                             

                            Can you inspect the incoming request to see if any of the headers are bung?

                             

                            Are you sure your host header for your website has the exact domain name the <cfhttp> request is... err... requesting?  And that you're making the request on the same port, and IP address as the host header is configured for?

                             

                            I really doubt <cfhttp> is the culprit here - at least in the way you're suggesting - because almost every web server in existence will be serving more than one website, and it's not like <cfhttp> usually has this problem...

                             

                            --

                            Adam

                            • 11. Re: CFHTTP problem with Host Headers
                              Adam Cameron. Level 5

                              Oh, and what happens if you set a userAgent string to reflect "common" browser?  I've had web sites set to reject requests coming in from dodgy-looking user agents, and indeed have refused requests from <cfhttp> (which passes a User-Agent value of "ColdFusion").  I usually get a different error than you're seeing though... I don't recall what it is, but it's not what you're seeing.

                               

                              --

                              Adam

                              • 12. Re: CFHTTP problem with Host Headers
                                doncx Level 1

                                Adam -

                                 

                                Thanks for your flurry of very valuable ideas.  I'll work my way through them and update this thread. 

                                 

                                Thanks also for your obscure and interesting usage of the word "conceit", which sent me to the dictionary - something I always enjoy.

                                • 13. Re: CFHTTP problem with Host Headers
                                  Adam Cameron. Level 5

                                  Thanks also for your obscure and interesting usage of the word "conceit", which sent me to the dictionary - something I always enjoy.

                                   

                                  Haha, cool.  You're welcome.

                                   

                                  --

                                  Adam

                                  • 14. Re: CFHTTP problem with Host Headers
                                    BKBK Adobe Community Professional & MVP

                                    Let cfhttp post to the full URL of the form page, http://www.mydomain.tld/forms/includes/form1.cfm

                                    • 15. Re: CFHTTP problem with Host Headers
                                      doncx Level 1

                                      My thanks.  The problem is resolved.

                                       

                                      In the end, I think I was sending a trailing slash with the domain name in the host header.

                                       

                                      Embarrassing, yes.

                                       

                                      Again, thank you for your (and BKBK's) assistance.

                                       

                                      - Don

                                      • 16. Re: CFHTTP problem with Host Headers
                                        Adam Cameron. Level 5

                                        Nah, not embarrassing.  For all the confidence in my post about TCP/IP and HTTP before, I had to go read up on the protocol stacks and how they worked, and do some experimentation with <cfhttp> and Firefox and pick apart some HTTP requests and such like.  I thought I new how it all worked when I sat down to reply, but I was really wrong in some of my assumptions as it turns out.  So it was a good learning experience for me too.

                                         

                                        It's always easy in this sort of thing to mix up what's a domain name (no slashes) and what's part of a URL (can contain slashes obviously), and I bet everyone has done what you just did at least once.  I know I have.

                                         

                                        Take it easy.

                                         

                                        --

                                        Adam