home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / cfhttp.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  2.0 KB  |  68 lines

  1. <!--- This example shows the use of CFHTTP to pull information
  2. dynamically from the snippets directory --->
  3. <HTML>
  4. <HEAD>
  5. <TITLE>
  6. CFHTTP Example
  7. </TITLE>
  8. </HEAD>
  9.  
  10. <BODY>
  11. <H3>CFHTTP Example</H3>
  12. <P>This example shows the ability of CFHTTP to pull
  13. the contents of a web resource from the Internet 
  14. or from a local directory.
  15.  
  16. <FORM ACTION="cfhttp.cfm" METHOD="POST">
  17. Try entering a URL for the tag to return:
  18. <INPUT TYPE="Text" size=25 NAME="urladdress" VALUE="http://www.allaire.com">
  19. <INPUT TYPE="Submit" NAME="" VALUE="get page">
  20. </FORM>
  21.  
  22. <!--- sets a default value for a URL to retrieve --->
  23. <!--- If this example fails to run correctly, you may need to 
  24.       change localhost to the name
  25.       of the CF Server that contains CFDOCS --->
  26. <CFPARAM name="urladdress" default="http://localhost/cfdocs/index.htm">
  27.  
  28. <!--- if we have passed a url address in the form, we
  29. want to display the passed address --->
  30. <CFIF IsDefined("form.urladdress") is True>
  31. <!--- do simple error check to avoid crashing the
  32. tag --->
  33.     <CFIF #Trim("#Form.urladdress#")# is "" or #Trim("#Form.urladdress#")# is "http://">
  34. <!--- if error condition tripped, set alternative --->
  35.         <CFSET urlAddress ="http://localhost/cfdocs/index.htm">
  36.         <H4>because you entered no url or an empty string, the tag
  37.         will return the following address: http://localhost/cfdocs/index.htm</H4>
  38.  
  39.     <CFELSE>
  40. <!--- otherwise use address passed from form --->
  41.         <CFSET urlAddress = "#form.urladdress#">
  42.     </CFIF>
  43. <!--- now use the CFHTTP tag to get the file content
  44. represented by urladdress --->    
  45.         <CFHTTP URL="#urladdress#"
  46.             METHOD="GET"
  47.             RESOLVEURL=YES>
  48.         </CFHTTP>
  49. <CFELSE>
  50. <!--- the first time through, retrieve a URL that we know
  51. exists --->
  52. <CFHTTP URL="http://localhost/cfdocs/index.htm"
  53.     METHOD="GET"
  54.     RESOLVEURL=YES>
  55. </CFHTTP>
  56. </CFIF>
  57.  
  58. <!--- Now, output the file, including the mimetype and content --->
  59. <H3>Show the file</H3>
  60.  
  61. <CFOUTPUT>
  62. <P>Your file was of type: #CFHTTP.MimeType#
  63. <P>#HTMLCodeFormat(CFHTTP.FileContent)#
  64. </CFOUTPUT>
  65.  
  66. </BODY>
  67. </HTML>       
  68.