Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFHTTP & URL error

Status
Not open for further replies.

aleci

Programmer
May 22, 2001
40
GB
Hi all,
I am working on retrieving news content from the 'Guardian-Unlimited' site.

If the URL doesnt work through technical problems,i want to be able to abort the retrieval and display previous news already stored in a DB instead.

Can CFHTTP 'test' the given URL prior to executing the retrieval??

My code is as follows:

<!--deletes previously stored news-->
<cfquery name=&quot;delete_all_records&quot; datasource=&quot;guardian&quot; dbtype=&quot;ODBC&quot;>
DELETE FROM news
</cfquery>

<!--Retrieval-->
<cfhttp method=&quot;get&quot;
url=&quot; path=&quot;C:\My Documents\Alexis\Guardian\&quot; file=&quot;guardian.txt&quot;>

<CFFILE ACTION=&quot;Read&quot; FILE=&quot;C:\My Documents\Alexis\Guardian\guardian.txt&quot; VARIABLE=&quot;news&quot;>

<CFOUTPUT>
#news#
</CFOUTPUT>

thanks in advance for any help
 
If you add &quot;ThrownOnError to your CFHTTP tag (I also added a timeout of 5 seconds) then you can use CFTRY/CFCATCH


<CFSET vDelete = Yes>

<CFTRY>

<!--Retrieval-->
<cfhttp method=&quot;get&quot;
url=&quot; path=&quot;C:\My Documents\Alexis\Guardian\&quot; file=&quot;guardian.txt&quot; TIMEOUT=&quot;5&quot; THROWONERROR=&quot;Yes&quot;>

<CFCATCH TYPE=&quot;Any&quot;>
Could Not Find File
<CFSET vDelete = No>
</CFCATCH>

</CFTRY>

<CFIF vDelete>
<!--deletes previously stored news-->
<cfquery name=&quot;delete_all_records&quot; datasource=&quot;guardian&quot; dbtype=&quot;ODBC&quot;>
DELETE FROM news
</cfquery>

<CFFILE ACTION=&quot;Read&quot; FILE=&quot;C:\My Documents\Alexis\Guardian\guardian.txt&quot; VARIABLE=&quot;news&quot;>

<CFOUTPUT>
#news#
</CFOUTPUT>

<CFELSE>
<!--deletes previously stored news-->
<cfquery name=&quot;qNews&quot; datasource=&quot;guardian&quot; dbtype=&quot;ODBC&quot;>
SELECT * FROM news
</cfquery>

<CFOUTPUT QUERY=&quot;qNews&quot;>
#news#
</CFOUTPUT>
</CFIF>
- tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top