s c h e m a t i c s : c o o k b o o k

/ WebProgramming? / Cookbook.WebFetchingURL

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Fetching a URL

Problem

You want to get the web page stored at a URL (web address), such as http://schematics.sourceforge.net/

Solution

The url.ss library in the net collection provides support for opening URLs. The following program opens a URL and displays the HTML that makes up the HTTP body.

(require (lib "url.ss" "net"))

(display-pure-port
 (get-pure-port
  (string->url "http://schematics.sourceforge.net/")))

Discussion

If you want to retain the HTTP headers use the get-impure-port function.

(require (lib "url.ss" "net"))

(get-impure-port
 (string->url "http://schematics.sourceforge.net/"))

To get the headers from an impure-port, you purify it.

(require (lib "url.ss" "net"))

(purify-port
 (get-impure-port
  (string->url "http://schematics.sourceforge.net/")))

If you're behind a proxy server, you'll need to set a proxy with current-proxy-servers, which also can be called without arguments to display the current settings:

> (current-proxy-servers '(("http" "proxy.example.com" 8101)))
> (current-proxy-servers)
(("http" "proxy.example.com" 8101))

To retrieve a URL using the HTTPS protocol, see WebFetchingHttpsUrl.

-- JensAxelSoegaard

-- GordonWeakliem - 20 Apr 2004

CookbookForm
TopicType: Recipe
ParentTopic: WebRecipes
TopicOrder: 010

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest