mirko
11-20-2004, 01:46 AM
Originally posted by "ditto"
I What is cfhttp ?
-----------------
CFHTTP simply allows you to capture information from other web sites using the http protocol.
What it means is that it allows you to grab data from other web site
such as news, weather reports, headlines,...etc
For example if you looked at the index page of this site,
you will noticed that there were headlines from TheRegister.
II Syntax explained
--------------------
First you might want study the syntax and there various attributes a bit.
If it looks confusing do not worry, I will explain some of the more important attributes.
<cfhttp
url = "hostname"
port = "port_number"
method = "get_or_post"
username = "username"
password = "password"
name = "queryname"
columns = "query_columns"
path = "path"
file = "filename"
delimiter = "character"
textQualifier = "character"
resolveURL = "yes" or "no"
proxyServer = "hostname"
proxyPort = "port_number"
userAgent = "user_agent"
throwOnError = "yes" or "no"
redirect = "yes" or "no"
timeout = "timeout_period">
</cfhttp>
Port (Optional, defaults is 80)
- The port the remote web server bind to (80 by default)
- Only on rare occasions you will need to change this.
Method (Optional, defaults is GET)
- Get (default) or Post (To work with forms) Path (Optional)
- The full path name you would like the save the retrieved content to.
- Required in a POST operation if path is specified
ResolveURL(Optional,defaults is No)
- If you want the links to remain intact from the page you are fetching set this attribute to yes.
- If you do not need them leave set it to no (default), it will improve performance.
proxyServer (Optional)
-If you are behind a proxy server enter the host name or IP address here.
proxyPort ( Optional, default is 80)
-If the proxy server is bind to another port enter it here.
Timeout (optional)
-A value in seconds that the coldfusion server is allowed to wait before a request is set to timeout.
III Examples
--------------
Imagine you were asked to create a local copy of the CNN home page for intranet viewing.
First we will lookup the IP which is 216.115.102.78 (see Usage Tips/Notes on why).
<cfhttp
url="207.25.71.27"
method="GET"
port="80"
resolveurl="yes"
timeout="10"
throwonerror="yes"
/>
After the page has been fetched you can do two things,
either output it with <cfoutput>#cfhttp.filecontent#</cfoutput>
or let cfhttp write the contents to a file with the URL and path attribute.
example :
<cfhttp
URL="207.25.71.27"
method="GET"
path="c:\inetpub\wwwroot\"
file="CNNhomePage.html"
timeout="10"
ResolveURL="Yes"
/>
This will create a file called CNNhomePage.html in the specified directory
Note that you can fetch binary data just as easy.
Of course there is no sense in displaying binary data in a browser,
so most likely you would be saving the retrieved content to a directory.
<cfhttp
URL=http://www.myhost.com/myzip.zip
method="GET"
path="d:\"
file="test.zip"
timeout="10"
ResolveURL="No"
/>
In one of the next tutorials I will cover some of the more advanced features of cfhttp
as well as using cfhttp to build up a query.
Usage Tips/Notes
-------------------
Use IP addresses instead of host names when possible,
this allows the cfhttp tag to operate normally if a name server lookup would fail.
Always specify a timeout, if there is no timeout specified in the cfhttp
attribute and no timeout in the administrator the coldfusion server will
wait indefinitely for the request to complete.
If the coldfusion server then reaches the number of simultaneous (as defined in the administrator)
requests the coldfusion server will hang.
(Meaning that the coldfusion server will not process any new requests,
as it will be waiting for the request to complete)
Do not set resolveURL to true unless you really need to have fully resolved url's.
(You will notice a performance decrease if set to true).
I What is cfhttp ?
-----------------
CFHTTP simply allows you to capture information from other web sites using the http protocol.
What it means is that it allows you to grab data from other web site
such as news, weather reports, headlines,...etc
For example if you looked at the index page of this site,
you will noticed that there were headlines from TheRegister.
II Syntax explained
--------------------
First you might want study the syntax and there various attributes a bit.
If it looks confusing do not worry, I will explain some of the more important attributes.
<cfhttp
url = "hostname"
port = "port_number"
method = "get_or_post"
username = "username"
password = "password"
name = "queryname"
columns = "query_columns"
path = "path"
file = "filename"
delimiter = "character"
textQualifier = "character"
resolveURL = "yes" or "no"
proxyServer = "hostname"
proxyPort = "port_number"
userAgent = "user_agent"
throwOnError = "yes" or "no"
redirect = "yes" or "no"
timeout = "timeout_period">
</cfhttp>
Port (Optional, defaults is 80)
- The port the remote web server bind to (80 by default)
- Only on rare occasions you will need to change this.
Method (Optional, defaults is GET)
- Get (default) or Post (To work with forms) Path (Optional)
- The full path name you would like the save the retrieved content to.
- Required in a POST operation if path is specified
ResolveURL(Optional,defaults is No)
- If you want the links to remain intact from the page you are fetching set this attribute to yes.
- If you do not need them leave set it to no (default), it will improve performance.
proxyServer (Optional)
-If you are behind a proxy server enter the host name or IP address here.
proxyPort ( Optional, default is 80)
-If the proxy server is bind to another port enter it here.
Timeout (optional)
-A value in seconds that the coldfusion server is allowed to wait before a request is set to timeout.
III Examples
--------------
Imagine you were asked to create a local copy of the CNN home page for intranet viewing.
First we will lookup the IP which is 216.115.102.78 (see Usage Tips/Notes on why).
<cfhttp
url="207.25.71.27"
method="GET"
port="80"
resolveurl="yes"
timeout="10"
throwonerror="yes"
/>
After the page has been fetched you can do two things,
either output it with <cfoutput>#cfhttp.filecontent#</cfoutput>
or let cfhttp write the contents to a file with the URL and path attribute.
example :
<cfhttp
URL="207.25.71.27"
method="GET"
path="c:\inetpub\wwwroot\"
file="CNNhomePage.html"
timeout="10"
ResolveURL="Yes"
/>
This will create a file called CNNhomePage.html in the specified directory
Note that you can fetch binary data just as easy.
Of course there is no sense in displaying binary data in a browser,
so most likely you would be saving the retrieved content to a directory.
<cfhttp
URL=http://www.myhost.com/myzip.zip
method="GET"
path="d:\"
file="test.zip"
timeout="10"
ResolveURL="No"
/>
In one of the next tutorials I will cover some of the more advanced features of cfhttp
as well as using cfhttp to build up a query.
Usage Tips/Notes
-------------------
Use IP addresses instead of host names when possible,
this allows the cfhttp tag to operate normally if a name server lookup would fail.
Always specify a timeout, if there is no timeout specified in the cfhttp
attribute and no timeout in the administrator the coldfusion server will
wait indefinitely for the request to complete.
If the coldfusion server then reaches the number of simultaneous (as defined in the administrator)
requests the coldfusion server will hang.
(Meaning that the coldfusion server will not process any new requests,
as it will be waiting for the request to complete)
Do not set resolveURL to true unless you really need to have fully resolved url's.
(You will notice a performance decrease if set to true).