Example

Fetch Web Pages (Web HTTP Files)

Author: Carl Sassenrath
Return to REBOL Cookbook

This example fetches a web page (transfers web page using HTTP) and stores it to a local file.

For text files such as HTML, use the READ function to fetch the page and WRITE to save it to a file:


    data: read http://www.rebol.com/docs.html
    write %docs.html data

For binary files such as images or programs, add the /binary refinement:


    data: read/binary http://www.rebol.com/graphics/rebol-logo.gif
    write/binary %logo.gif data

Do not forget to use /binary for these types of files, otherwise they will not be properly fetched and stored.

It is safe to always use /binary if you are unsure what type of file it is.

Notes
  • Text files will automatically have their line terminators converted to the format used by your local computer.
  • The /binary refinement disables the line terminator conversion.
  • If the URL does not exist, you will get an error (e.g. 404) or a text message depending on how the target web server is configured.

That's all there is to fetching web pages. Easy.


2006 REBOL Technologies REBOL.com REBOL.net