[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8 HTTP

Procedures for connecting via HTTP

An example of using these procedures is shown as follows.

; when you will establish a connection by GET method
(define con
  (make-http-connection "http://localhost/path"))
(http-properties-set! con '((request-method . get)))
(http-connect con)
(define pp
  (open-http-input-port
    con
    (buffer-mode block)
    (make-transcoder (utf-8-codec) (eol-style crlf))))
(get-line pp)
(close-port pp)
(disconnect-http con)

; when you will establish a connection by POST method
(define con
  (make-http-connection "http://localhost/path"))
(http-properties-set! con '((request-method . post)))
(post-http-parameter  ; setting parameters
  con
  '(("test1" . "aaaaaa")
    ("test2" . "bbbbb")))
(http-connect con)
(define pp
  (open-http-input-port
    con
    (buffer-mode block)
    (make-transcoder (utf-8-codec) (eol-style crlf))))
(get-line pp)
(close-port pp)
(disconnect-http con)
Function: make-http-connection url

creates an HTTP connection.
raises an exception when a protocol of the URL is not HTTP(S).

Function: http-properties-set! connection properties

sets properties to the connection.
Syntax for setting properties is shown as follows.

((property-name . string)
 ...)

property-name is a symbol or a string shown as follows.

request-methodan HTTP method (GET or POST)
allow-user-interatctionallow-user-interatction
if-modified-sinceif-modified-since
use-cachesuse-caches
chunked-streaming-modechunked-streaming-mode
fixed-length-streaming-modefixed-length-streaming-mode
Function: post-http-parameter connection parameters

posts parameters to the connection.
Parameters must be an associative list of strings.

Function: http-connect connection

establishs the HTTP connection.
This procedure returns two values, the first argument is #t if establishing a connection is succeed and the second is an HTTP request code such as 400.

Function: http-content-encoding connection
Function: http-content-length connection
Function: http-content-type connection
Function: http-date connection
Function: http-expiration connection
Function: http-last-modified connection

gets a encoding, length, content-type, date, expiration date, last modified date of the connection, respectively.

Function: http-headers connection

gets all header informations by the associative list.

Function: open-http-input-port connection buffer-mode transcoder

creates an input port of the connection.
buffer-mode and transcoder specifies the R6RS buffer mode and transcoder, respectively. If trancoder is #f, a port to be created will be a binary port.

Function: disconnect-http connection

closes the HTTP connection.

Function: web-get url filename

gets a file from the URL via HTTP.


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on August 9, 2012 using texi2html 5.0.