* A question about http-get of (web client)
@ 2012-04-26 1:15 Sunjoong Lee
2012-04-26 12:50 ` Sunjoong Lee
0 siblings, 1 reply; 3+ messages in thread
From: Sunjoong Lee @ 2012-04-26 1:15 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]
First, here is an example of http-get:
(use-modules ((web uri) #:select (string->uri))
((web client) #:select (http-get)))
(call-with-values (lambda ()
(http-get
(string->uri "http://www.gnu.org/software/guile/")))
(lambda (res-headers res-body)
(display res-body)
(newline)))
It works well. But after changing url string from "
http://www.gnu.org/software/guile/" to "http://www.gnu.org/", it did not
work. Last two lines of Backtrace is:
web/http.scm:184:11: In procedure read-header:
web/http.scm:184:11: Throw to key `bad-header' with args `(uri
"home.html")'.
I think http://www.gnu.org/ need to know browser's encoding language.
http-get accept extra-headers but I don't know how to fill the contents of
headers in web and scheme. In scheme, I think acon magic(?) is needed.
Please show me an example to fill headers. I want to fill browser's
encoding language, browser's type and some cookies. Oh, cookie would be
need if http://www.google.com/ , I think, and would be got
from res-headers.
[-- Attachment #2: Type: text/html, Size: 1640 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A question about http-get of (web client)
2012-04-26 1:15 A question about http-get of (web client) Sunjoong Lee
@ 2012-04-26 12:50 ` Sunjoong Lee
2012-04-27 14:20 ` Sunjoong Lee
0 siblings, 1 reply; 3+ messages in thread
From: Sunjoong Lee @ 2012-04-26 12:50 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 3723 bytes --]
I suspect "ISO-8859-1" make a problem. open-socket-for-uri of (web client)
sets encoding of port to "ISO-8859-1". read-response of (web response)
also sets encoding of port to "ISO-8859-1".
(use-modules ((srfi srfi-11) #:select (let-values))
((web uri) #:select (string->uri))
((web client) #:select (http-get)))
(let-values (((res-headers res-body)
(http-get (string->uri "http://www.gnu.org/home.html")
#:extra-headers
(acons 'Accept "text/html"
(acons 'Accept-Charset "ISO-8859-1"
(acons 'Accept-Language "en-US"
'()))))))
(display res-body)
(newline))
Above code makes an error:
...
In web/response.scm:
187: 2 [read-response #<input-output: socket 5>]
In web/http.scm:
218: 1 [lp ((server . "Apache/2.2.14") (date . #))]
184: 0 [read-header #<input-output: socket 5>]
Same error after changing above "ISO-8859-1" to "utf-8" of course; It's
meaningless.
(let-values (((res-headers res-body)
(http-get (string->uri "http://www.gnu.org/home.html")
#:extra-headers
(acons 'Accept "text/plain" '()))))
(display res-body)
(newline))
Above code display this:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /home.html
could not be found on this server.</p>
Available variants:
<ul>
<li><a href="home.ar.html">home.ar.html</a> , type text/html, language
ar</li>
...
406 Not Acceptable? I think 'Accept "text/html" and 'Accept-Language
"en-US" will be need. But, "text/html" makes a above error!!
After changing (display res-body) to (display res-headers):
#<<response> version: (1 . 1) code: 406 reason-phrase: "Not Acceptable"
headers: ((date . #<date nanosecond: 0 second: 52 minute: 34 hour: 12 day:
26 month: 4 year: 2012 zone-offset: 0>) (server . "Apache/2.2.14")
(alternates . "{\"home.ar.html\" 1 {type text/html} {language ar}},
{\"home.bg.html\" 1 {type text/html} {language bg}}, {\"home.ca.html\" 1
{type text/html} {language ca}}, {\"home.cs.html\" 1 {type text/html}
{language cs}}, {\"home.de.html\" 1 {type text/html} {language de}},
{\"home.el.html\" 1 {type text/html} {language el}}, {\"home.es.html\" 1
{type text/html} {language es}}, {\"home.fa.html\" 1 {type text/html}
{language fa}}, {\"home.fr.html\" 1 {type text/html} {language fr}},
{\"home.html\" 1 {type text/html} {language en}}, {\"home.id.html\" 1 {type
text/html} {language id}}, {\"home.it.html\" 1 {type text/html} {language
it}}, {\"home.ja.html\" 1 {type text/html} {language ja}},
{\"home.kn.html\" 1 {type text/html} {language kn}}, {\"home.ko.html\" 1
{type text/html} {language ko}}, {\"home.nb.html\" 1 {type text/html}
{language nb}}, {\"home.nl.html\" 1 {type text/html} {language nl}},
{\"home.pl.html\" 1 {type text/html} {language pl}}, {\"home.pt-br.html\" 1
{type text/html} {language pt-br}}, {\"home.ro.html\" 1 {type text/html}
{language ro}}, {\"home.ru.html\" 1 {type text/html} {language ru}},
{\"home.sq.html\" 1 {type text/html} {language sq}}, {\"home.sr.html\" 1
{type text/html} {language sr}}, {\"home.tr.html\" 1 {type text/html}
{language tr}}, {\"home.uk.html\" 1 {type text/html} {language uk}},
{\"home.zh-cn.html\" 1 {type text/html} {language zh-cn}}") (vary negotiate
accept-language accept-encoding) (tcn . "list") (content-length . 2425)
(connection close) (content-type text/html (charset . "iso-8859-1"))) port:
#<closed: file 0>>
[-- Attachment #2: Type: text/html, Size: 5984 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: A question about http-get of (web client)
2012-04-26 12:50 ` Sunjoong Lee
@ 2012-04-27 14:20 ` Sunjoong Lee
0 siblings, 0 replies; 3+ messages in thread
From: Sunjoong Lee @ 2012-04-27 14:20 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]
I think I found the cause of the error; the error was in
declare-uri-header! That was not a encoding problem.
http://www.gnu.org/home.html will send Content-Location header and it is
home.en.html if your Accept-Language is en-US. Yes!! This is a relativeURI.
Location is absolute URI but Content-Location and Referer may be relative
URI or absolute URI. Current declare-uri-header! can do only absolute URI
because string->uri returns false value whenever not absolute URI!!
2012/4/26 Sunjoong Lee <sunjoong@gmail.com>
>
> (use-modules ((srfi srfi-11) #:select (let-values))
> ((web uri) #:select (string->uri))
> ((web client) #:select (http-get)))
> (let-values (((res-headers res-body)
> (http-get (string->uri "http://www.gnu.org/home.html")
> #:extra-headers
> (acons 'Accept "text/html"
> (acons 'Accept-Charset "ISO-8859-1"
> (acons 'Accept-Language "en-US"
> '()))))))
> (display res-body)
> (newline))
>
> Above code makes an error:
> ...
> In web/response.scm:
> 187: 2 [read-response #<input-output: socket 5>]
> In web/http.scm:
> 218: 1 [lp ((server . "Apache/2.2.14") (date . #))]
> 184: 0 [read-header #<input-output: socket 5>]
>
[-- Attachment #2: Type: text/html, Size: 2843 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-04-27 14:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-26 1:15 A question about http-get of (web client) Sunjoong Lee
2012-04-26 12:50 ` Sunjoong Lee
2012-04-27 14:20 ` Sunjoong Lee
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).