unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Chris Vine <chris@cvine.freeserve.co.uk>
To: Guile User <guile-user@gnu.org>
Subject: Using guile's web client
Date: Thu, 15 Mar 2012 00:05:54 +0000	[thread overview]
Message-ID: <20120315000554.6e1918df@laptop.homenet> (raw)

Hi,

I have been playing around with guile-2.0.5's high-level web modules.
In order to see if I understood them, I tried about the simplest thing
I could think of: a GET request to checkip.dyndns.com to obtain my IP
address.

The following code works correctly provided I leave the commented out
code commented out:

(use-modules
 (web uri)
 (web response)
 (rnrs bytevectors)
 (web client))

((lambda()
   (let ((uri (build-uri 'http
                         #:host "checkip.dyndns.com"
                         #:port 80
                         #:path "/")))
     (display uri)
     (newline)
     (let ((r (http-get uri #:keep-alive? #t)))
       (if r
           (begin
             (display r)(newline)
;;           (display (read-response-body r))(newline)
             )
           (begin
             (display "Can't obtain response body")
             (newline)))))))

It outputs:

#<<uri> scheme: http userinfo: #f host: "checkip.dyndns.com" port: 80 path: "/" query: #f fragment: #f>
#<<response> version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((content-type text/html) (server . "DynDNS-CheckIP/1.0") (connection close) (cache-control no-cache) (pragma no-cache) (content-length . 105)) port: #<input-output: socket 6>>

The contents of the response object mirrors the response obtained by
node.js with the equivalent code written in javascript, including the
content length, so the response object appears to be correct.  However,
if I try to obtain the response body by uncommenting the call to
read-response-body, I get an error:

Backtrace:
In ice-9/boot-9.scm:
 149: 10 [catch #t #<catch-closure 81e9280> ...]
 157: 9 [#<procedure 81b38c0 ()>]
In unknown file:
   ?: 8 [catch-closure]
In ice-9/boot-9.scm:
  63: 7 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
 407: 6 [eval # #]
In ice-9/boot-9.scm:
2111: 5 [save-module-excursion #<procedure 81a1060 at ice-9/boot-9.scm:3646:3 ()>]
3653: 4 [#<procedure 81a1060 at ice-9/boot-9.scm:3646:3 ()>]
In unknown file:
   ?: 3 [load-compiled/vm "/home/chris/.cache/guile/ccache/2.0-LE-4-2.0/home/chris/src/scheme/my-ip-test.scm.go"]
In /home/chris/src/scheme/my-ip-test.scm:
  18: 2 [#<procedure 81ffd90 ()>]
In web/response.scm:
 223: 1 [read-response-body #]
In unknown file:
   ?: 0 [bytevector-length #<eof>]

ERROR: In procedure bytevector-length:
ERROR: In procedure scm_c_bytevector_length: Wrong type argument in position 1 (expecting bytevector): #<eof>

The error is in the procedure call to read-response-body.  Is this a
bug in guile-2, or am I doing something wrong?

Chris



             reply	other threads:[~2012-03-15  0:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-15  0:05 Chris Vine [this message]
2012-03-15  1:14 ` Using guile's web client Ian Price
2012-03-15 10:40   ` Chris Vine
2012-03-15 12:42     ` Ian Price
2012-03-15  1:43 ` Nala Ginrut
2012-03-15  2:11   ` Ian Price
2012-03-15  3:55     ` Nala Ginrut
2012-03-15  4:01       ` Nala Ginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120315000554.6e1918df@laptop.homenet \
    --to=chris@cvine.freeserve.co.uk \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).