* http-read with cookie
@ 2012-05-06 7:39 Sunjoong Lee
0 siblings, 0 replies; only message in thread
From: Sunjoong Lee @ 2012-05-06 7:39 UTC (permalink / raw)
To: guile-user
[-- Attachment #1.1: Type: text/plain, Size: 5585 bytes --]
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:
#<<response> 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 nanosecond: 0 second: 41 minute: 20 hour: 23 day: 5
month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second: 9
minute: 3 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires .
#<date nanosecond: 0 second: 9 minute: 3 hour: 7 day: 6 month: 5 year: 2012
zone-offset: 0>) (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: #<closed: file
0>>
#<<response> 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 nanosecond: 0 second: 46 minute: 32 hour: 4 day: 6
month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second:
10 minute: 3 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires .
#<date nanosecond: 0 second: 10 minute: 3 hour: 7 day: 6 month: 5 year:
2012 zone-offset: 0>) (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: #<closed: file
0>>
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:
#<<response> 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 nanosecond: 0 second: 46 minute: 32 hour: 4 day: 6
month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second:
58 minute: 23 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires
. #<date nanosecond: 0 second: 58 minute: 23 hour: 7 day: 6 month: 5 year:
2012 zone-offset: 0>) (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: #<closed: file
0>>
#<<response> 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 nanosecond: 0 second: 46 minute: 32 hour: 4 day: 6
month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second:
58 minute: 23 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires
. #<date nanosecond: 0 second: 58 minute: 23 hour: 8 day: 6 month: 5 year:
2012 zone-offset: 0>) (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: #<closed: file 0>>
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.
[-- Attachment #1.2: Type: text/html, Size: 7238 bytes --]
[-- Attachment #2: http-read.scm.gz --]
[-- Type: application/x-gzip, Size: 2301 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-05-06 7:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-06 7:39 http-read with cookie 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).