[racket] retrieving an https url
I have modernized the language (not really necessary) and adapted
the example so that it does something useful (not very) with a real https
url. See below. It's all in one drracket buffer to make it more
easily readable. I am sure you can split it up into separate files.
Basically all exports documented at
http://docs.racket-lang.org/net/url.html?q=url#(def._((lib._net/url-structs..rkt)._url))
are available prefixed with ssl: and you can contact web sites via post and other
methods as explained there.
hth -- Matthias
#lang racket/load
(module ssl-url.ss racket
;; From Eli Barzilay
;; This will give us ssl:--- for an ssl version of url.ss, but still need an
;; explicit port number specification since url.ss does not handle that
(require racket/unit
net/url-sig net/url-unit
net/tcp-sig net/tcp-unit
net/ssl-tcp-unit)
(define-values/invoke-unit (compound-unit/infer (import) (export url^) (link tcp@ url@))
(import)
(export url^))
(define ssl-tcp@ (make-ssl-tcp@ #f #f #f #f #f #f #f))
(define-values/invoke-unit
(compound-unit (import) (export URL)
(link [((TCP : tcp^)) ssl-tcp@]
[((URL : url^)) url@ TCP]))
(import)
(export (prefix ssl: url^)))
(provide (all-defined-out))
)
(module sample-client racket/gui
; (require "ssl-url.ss")
(require 'ssl-url.ss)
(define LOGIN "https://myneu.neu.edu/myneu/login/lock.gif")
(ssl:call/input-url
(string->url LOGIN)
ssl:get-pure-port
(lambda (ip)
(define file "login-image.gif")
(with-output-to-file file (lambda () (copy-port ip (current-output-port))) #:exists 'replace)
(make-object image-snip% file 'gif))))
(require 'sample-client)
On Jun 17, 2011, at 11:17 PM, Jordan Schatz wrote:
> I am still pretty new to Racket, I've built a few trivial projects and am
> now jumping into a more serious app. One of the first things I need to be
> able to do though is work with (as a client, not server) https urls. GET
> PUT POST HEAD DELETE, and most of the time send special headers.
>
> I have seen these:
> http://docs.racket-lang.org/openssl/index.html?q=ssl
> http://docs.racket-lang.org/net/url.html?q=put&q=ssl#(def._((lib._net/url..rkt)._get-pure-port))
> http://schemecookbook.org/view/Cookbook/WebFetchingHttpsUrl
>
> I think those are all the pieces I need but I don't really understand
> racket's unit system, and that last link appears abit dated.
>
> Is the technique mentioned in WebFetchingHttpsUrl still the right way to
> do things? Do I need to update this to #lang racket? is there a
> better/more proper way?
>
> Thanks much!
> Jordan
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users