Copy link to clipboard
Copied
<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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Hi ilssac,
Yes you are correct , but my main problem is the text file exists in the server but i am getting message that file is not found when i use url directly in browser i am able to display but when i am trying to call from cfhttp i am getting message file not foung like 404 Not Found.
this is what i need to solve now.
Copy link to clipboard
Copied
The username that is used to start the ColdFusion service (in control panel / services on the server) must have rights to read the file on the server in
question. If it does not, you will get an error.
This could be why you can see the file when typing the address into your computer, but the ColdFusion server gets an error.
Copy link to clipboard
Copied
Hi
May be we think username is problem , but i had more file like test1.txt,test2.txt...etc, ia m seeing this error messgae file not found for only some files even they are in server and manually opening it.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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