Skip to content

Instantly share code, notes, and snippets.

@kobapan
Created April 6, 2020 02:33
Show Gist options
  • Save kobapan/b6b668f76219bc927263521b4e23538e to your computer and use it in GitHub Desktop.
Save kobapan/b6b668f76219bc927263521b4e23538e to your computer and use it in GitHub Desktop.
get html body with uri (Gauche Scheme lisp)
(use rfc.http) ; http-get http-compose-query
(use rfc.uri) ; uri-parse uri-compose
(define (uri-get uri :key (query #f))
(if query (set! uri (string-append uri (if (car query) (http-compose-query "" query)
#"&~(http-compose-query #f (cdr query))"))))
(receive (code status body)
(receive (scheme user-info hostname port path query frament)
(uri-parse uri)
(http-get hostname (uri-compose :path path :query query)))
body))
;; uri-get
;;
;; get html body with uri
;;
;; (use rfc.http)
;; (use rfc.uri)
;;
;; (uri-get "http://hoge.com/t/i?x=hoge&y=fuga")
;;
;; (uri-get "http://hoge.com/t/i"
;; :query '((x "hoge")
;; (y "fuga")))
;;
;; (uri-get "http://hoge.com/t/i?z=1"
;; :query '(#f
;; (x "hoge")
;; (y "fuga")))
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment