PasteRack.org
Paste # 41378
2018-08-09 05:38:36

Fork as a new paste.

Paste viewed 153 times.


Embed:

make http get request with basic auth

  1. #lang racket
  2.  
  3. (require net/url
  4.           net/base64)
  5.  
  6. (define (auth-request url user pass)
  7.   (let ([addr (if (string? url) (string->url url) url)]
  8.         [auth-header (format "Authorization: Basic ~a"
  9.                              (base64-encode
  10.                               (string->bytes/utf-8
  11.                                (format "~a:~a" user pass))))])
  12.     (get-pure-port addr (list auth-header))))

=>