Contents

class form-data

Overview

This class can be used to post forms using the multipart/form-data content-type. It can be used to act as a posting client, to post forms to websites, e.g. a MediaWiki.

Synopsys

 (require (planet "bot.scm" ("oesterholt" "webbot.plt" 1 0))
 (define F (form-data))
 (-> F form-add 'name "A name")
 (-> F form-add 'file (build-path "my-file.txt"))
 (let ((p (-> F form-post (string->url "http://test.form.org/post-it.php"))))
    (display (read-string 1000000 p))
    (close-input-port p))
 (exit)

Derived classes

Constructor: (form-data)

Takes no arguments

Public members

(cookies)

Returns the curren stored cookies, as they would be send to the http server.

(cookie c)

Returns #f, if c is not found, the value of the cookie of c otherwise

(cookie-match c)

Returns #f, if c is not matched, the value of the cookie of c otherwise

(form-add name value)

This member can be used to add a (form) field to be posted. It automatically does the right thing given it's input value. If value is of type path? the form will add the file to be uploaded; otherwise the string representation of the input value is taken (using format .

Input parameters: name:<symbol> , value:<anytype> .

Returns : this

(form-clear)

Clears the form. New fields can be added.

Returns : this

(form->bytes)

Converts the form to a 'bytes' representation.

Returns : The converted form

(form-post url)

Posts the form to the given url

Input parameters:  url:<url|string> (see the net collection)

Returns         :  <input-port> (can be used to read the results of the post

(post url)

Posts the form to the given url

Input parameters:  url:<url|string> (see the net collection)

Returns         :  <input-port> (can be used to read the results of the post

(get url)

Gets the page given by url :<url|string>

(basic-auth uid pass)

Sets uid and password for basic authorization.

(read-page port)

Reads the whole contents from the port returned by 'form-post' or 'post'