Skip to main content
Known Participant
August 26, 2010
Question

what is this mean

  • August 26, 2010
  • 3 replies
  • 1012 views

<cfhttp method="get" url="http://localhost:8500/projects/test.txt" timeout="5" />
   <cfset header = cfhttp.header />
   
    <cfif listContainsNoCase(header, "200 OK")>
        <cflocation url="http://localhost:8500/projects/test.txt">
    <cfelse>
        <cfset request.proginfo.pagemessage="The  file   was not found.">
        <cflocation url="search.cfm">
    </cfif>

hi the above is bit confusing i am relocating to search.cfm instead of opening url in cfhttp , but the file still exists on the same path and i am able to open it up with address  http://localhost:8500/projects/test.txt

any one had idea  about what it is doing?

Thanks

This topic has been closed for replies.

3 replies

Inspiring
August 30, 2010

Do this:
<cfhttp method="get" url="http://localhost:8500/projects/test.txt" timeout="5" />
<cfdump var=”# cfhttp#”>

That will display what returns from the cfhttp request. If that is not ‘200 OK’, if that is something else like 404, then your coldfusion server could not access localhost:8500. That happens base on the security settings in the web server. Try with the sever name or with the IP address. Some times that works.

If your test.txt and this cfm file in the server, you can use FileExists() function to check if the text file exists. That is way faster than cfhttp.

Thanks

Sam
cflove.org

Participant
August 26, 2010

Assuming you are taking this approach to check for existence of the file on a remote server instead of the server executing the CF code, try using method="HEAD" instead of "get". This will prevent the CFHTTP call from actually transferring the entire remote file content via CFHTTP and will be far more efficient since it will only transact on headers.

Also, keep in mind that under certain scenarios it is possible to get a 200 status code even when the file in question does not exist.

If the file is on the same physical server, test using fileexists("test.txt") instead of going through CFHTTP.

ilssac
Inspiring
August 26, 2010

I would be very interested in the WHY of this page....

It requests test.txt with <cfhttp....>

If that request returns a http "200 OK" response then relocate the current request to text.txt

Otherwise relocate the current request to search.cfm

tclaremont
Inspiring
August 26, 2010

It is checking to see if it can resolve text.txt. If it can, it shows it. If it cannot, it routes the visitor to search.

I am guessing that if it did not check for the satisfactory existance of the file, the end user would see a file not found message and be stuck, rather than being automatically forwarded to the search page.

This is just a guess, and I am NOT saying it makes sense!