Hello,
There is http-get in Guile and will be http-put, then what's the next? I
think the method using cookie and handling https. I had thought that I'd be
able to read contents of a web page needing login when I had read http-put
of Greg Benison,
http://lists.gnu.org/archive/html/guile-user/2012-04/msg00012.html .
How naive am I.
I recognize we need handling https because most login process of web pages
require it but have no idea of it now. During some trial, I made a very
little effort and want to share it. Of course, there shold be the better
way; I'm a newbie yet.
1.1 Exampe of http-get:
(receive (header body)
(http-get (string->uri "http://code.google.com/";))
(display header)
(newline))
(receive (header body)
(http-get (string->uri "http://code.google.com/";))
(display header)
(newline))
1.2 Output of above example:
#< version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary
accept-language cookie referer) (content-type text/html (charset .
"ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t)
(last-modified . #) (date . #) (expires .
#) (cache-control private (max-age . 3600))
(x-content-type-options . "nosniff") (set-cookie .
"PREF=ID=6d783c184a55e937:TM=1336287789:LM=1336287789:S=p7v3fPvc55hTb15k;
expires=Tue, 06-May-2014 07:03:09 GMT; path=/; domain=.google.com") (server
. "codesite_static_content") (x-xss-protection . "1; mode=block")
(x-frame-options . "SAMEORIGIN") (connection close)) port: #>
#< version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary
accept-language cookie referer) (content-type text/html (charset .
"ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t)
(last-modified . #) (date . #) (expires .
#) (cache-control private (max-age . 3600))
(x-content-type-options . "nosniff") (set-cookie .
"PREF=ID=e7e80585317f6678:TM=1336287790:LM=1336287790:S=PQWgTbaxsZyIqeVy;
expires=Tue, 06-May-2014 07:03:10 GMT; path=/; domain=.google.com") (server
. "codesite_static_content") (x-xss-protection . "1; mode=block")
(x-frame-options . "SAMEORIGIN") (connection close)) port: #>
1.3 Discussion about above output:
1) We need a web page using cookie. I picked http://code.google.com/ ; it
set PREF cookie once unlike http://www.google.com/ twice.
2) Example displays two headers, so the output is two line. In the first
line, http://code.google.com/ replied with set-cookie PREF. You may want to
send cookie header when the next request. If not so, the server would
re-send set-cookie PREF again as seen in second line.
3) Cookie header is essential when making a session. In above example, of
course, actually no need to making a session, so no need cookie, it's just
a test.
2.1 Example of http-read:
(receive (header body)
(http-read "http://code.google.com/";)
(display header)
(newline))
(receive (header body)
(http-read "http://code.google.com/";)
(display header)
(newline))
2.2 Output of above example:
#< version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary
accept-language cookie referer) (content-type text/html (charset .
"ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t)
(last-modified . #) (date . #) (expires
. #) (cache-control private (max-age . 3600))
(x-content-type-options . "nosniff") (set-cookie .
"PREF=ID=8253d36f6bcd8b99:TM=1336289038:LM=1336289038:S=xDYcthWhrVAC2asa;
expires=Tue, 06-May-2014 07:23:58 GMT; path=/; domain=.google.com") (server
. "codesite_static_content") (x-xss-protection . "1; mode=block")
(x-frame-options . "SAMEORIGIN") (connection close)) port: #>
#< version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary
accept-language cookie referer) (content-type text/html (charset .
"ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t)
(last-modified . #) (date . #) (expires
. #) (cache-control public (max-age . 3600))
(x-content-type-options . "nosniff") (server . "codesite_static_content")
(x-xss-protection . "1; mode=block") (x-frame-options . "SAMEORIGIN")
(connection close)) port: #>
2.3 Discussion about above output:
1) http-read can accept a string URL as it's first argument; of course, it
can accept a uri object like result of string->uri.
2) In the first line, the server replied with set-cookie PREF like 1.2 but
there is no second set-cookie PREF in the second line because http-read had
sent cookie header when second request.
I had attatched a code of http-read.
http-read.scm.gz
Description: GNU Zip compressed data