#lang racket
(require json net/head net/url net/cookies/user-agent)
(define (get-json-request url #:connection conn) (define req-headers (let ([cookies (cookie-header url)]) (cond [(false? cookies) '()] [else (list (format "Cookie: ~a" cookies))]))) (display (format "Headers sent were:\n ~a\n" req-headers)) (define-values (in-port resp-headers) (get-pure-port/headers url req-headers #:connection conn #:redirections 1)) (extract-and-save-cookies! (map string->bytes/utf-8 (string-split resp-headers "\r\n")) url) (display (format "\nReceived headers were:\n ~a" resp-headers)) (read-json in-port))
;; Start a session(define conn (make-http-connection))
;; Make a request that will force server to set cookies(displayln (jsexpr->string (get-json-request (string->url "https://postman-echo.com/cookies/set?foo1=bar1&foo2=bar2") #:connection conn)))
;; Make another request to see what cookies we sent server(displayln "\n--------------------------------------\n")(displayln (jsexpr->string (get-json-request (string->url "https://postman-echo.com/cookies") #:connection conn)))
;; Close session(http-connection-close conn)
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/f71ad314-677f-4f42-ae7c-9e738d88eded%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to racket...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/f71ad314-677f-4f42-ae7c-9e738d88eded%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
I did a web scraping in Racket a couple of months ago, and I agree that it is painful. On the bright side, Bogdan seems to start working on a practical requests-like library due to this thread, so we should have a good practical HTTP request library soon :)
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/21032250-5dc7-47eb-8e81-f4c2f6b9e52d%40googlegroups.com.