[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
HTTP Request/Response questions
From: |
R. P. Dillon |
Subject: |
HTTP Request/Response questions |
Date: |
Sat, 5 Nov 2011 22:49:25 -0700 |
I'm currently working on a project to gather RSS data using Guile. I've been working with both the stable 2.0.3 version and the latest git repository. I'm fairly new to Guile, though, so I might be approaching this the wrong way.
As a test, I wanted to make an HTTP request. This is a series of commands I executed in the REPL to accomplish this (using Geiser in Emacs 24):
(use-modules (web request) (web response) (web uri) (rnrs bytevectors))
(define port (socket PF_INET SOCK_STREAM 0))
(define address (addrinfo:addr (car (getaddrinfo "
www.google.com" "http"))))
(connect port address)
(define request (build-request (build-uri 'http #:host "
www.google.com")))
(write-request request port)
(define response (read-response port))
(read-response ...) consistently fails with Google:
web/http.scm:754:6: In procedure parse-asctime-date:
web/http.scm:754:6: Throw to key `bad-header' with args `(date "-1")'.
The expiration is set to -1 in the headers, and this seems to cause a problem for the web libraries in Guile.
This same request seems to work well for my own domain (
killring.org).
I attempted a very similar series of commands to get RSS data for Google News:
(define port (socket PF_INET SOCK_STREAM 0))
(define address (addrinfo:addr (car (getaddrinfo "
news.google.com" "http"))))
(connect port address)
(define request (build-request (build-uri 'http #:host "
news.google.com" #:path "/news?pz=1&cf=all&ned=us&hl=en&output=rss")))
(write-request request port)
(define response (read-response port))
(define body-vec (read-response-body response))
In this case, the (read-response-body ...) returns #f, although when I pulled the data manually, there was XML data present in the body of the response.
Similarly, when getting RSS information from Slashdot:
(define port (socket PF_INET SOCK_STREAM 0))
(connect port address)
(define request (build-request (build-uri 'http #:host "
rss.slashdot.org" #:path "/Slashdot/slashdot")))
(write-request request port)
(define response (read-response port))
I get the following error when reading the response:
web/http.scm:814:12: In procedure parse-entity-tag:
web/http.scm:814:12: Throw to key `bad-header' with args `(qstring "F+oOJMkOlp2n1IUbAJmq+7qCGuk")'.
which I haven't fully tracked down yet.
I have a feeling I'm using the API incorrectly, though I've pored over the documentation the best I can to figure out how to make these requests and parse the responses. Short of writing my own implementation, is there anything I should be doing to make this work?
Thanks,
Rick
- HTTP Request/Response questions,
R. P. Dillon <=