[plt-scheme] Re: post-pure-port

From: Mike MacHenry (dskippy at ccs.neu.edu)
Date: Fri Nov 16 17:01:46 EST 2007

Sorry, I forgot the requires:

(require
 (planet "htmlprag.ss" ("neil" "htmlprag.plt" 1 3))
 (lib "url.ss" "net")
 (lib "uri-codec.ss" "net"))

(define (post data)
  (html->sxml
   (post-pure-port
    (string->url "http://freerice.com/index.php")
    (string->bytes/utf-8 (alist->form-urlencoded data)))))

On Nov 16, 2007 4:59 PM, Mike MacHenry <dskippy at ccs.neu.edu> wrote:
> I'm trying to write a simple web-page-submitting script which will
> post data to a URL and get the response page back. I wrote the
> following function:
>
> (define (post urlstr data)
>   (html->sxml
>    (post-impure-port
>     (string->url urlstr)
>     (string->bytes/utf-8 (alist->form-urlencoded data)))))
>
> Invoking this with the URL of a test page I created and an assoc with
> one value in it doesn't seem to actually post the data. What I get
> back is an SXML representing the page as if I had invoked it without
> posting any data to it. A google search found me some more complicated
> code that used call/input-url which I adapted as follows:
>
> (define (post urlstr data)
>   (let ([post-data
>          (parameterize ([current-alist-separator-mode 'amp])
>            (string->bytes/utf-8
>             (alist->form-urlencoded data)))])
>     (call/input-url
>      (string->url urlstr)
>      (case-lambda
>        [(url) (post-pure-port url post-data)]
>        [(url los) (post-pure-port url post-data los)])
>      html->sxml)))
>
> This has the same behavior for me. I call it with an assoc that looks
> like '((test . "test value")) and the test page at the URL understands
> the 'test' argument but I get back SXML of the page without any data
> posted to it.
>
> Thanks for the help,
> -mike
>


Posted on the users mailing list.