[REBOL] Re: HTTP response header
From: hallvard::ystad::gmail::com at: 24-Mar-2006 0:32
(Sorry for duplicates of this email, if any)
Dixit Tim Johnson (22.07 23.03.2006):
Hi:
Is there a way to get the HTTP response header?
Here's the output from make money! .2 :
You could have a look at this script from the rebol.org library:
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=http-get.r&sid=k8wk
...or use the following script that I use, but it's based on
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=url-handler.r:
REBOL [
Title: "URL fetcher returning both content and headers of a URL"
File: %fetch-url.r
Author: [ "HY" ]
Date: 1-Jan-2005
History: [
1-Jan-2005 {Extracted the function into it's own file.}
]
]
do %url-handler.r
fetch-url: func [ full-url [string! url!] /headers header-block /local site
] [
to-fetch: url-handler to-string full-url
if not headers [header-block: [connection: close] ]
;to-insert: rejoin [ "GET " to-fetch/as-string/from-path-only "
HTTP/1.1^/Host: " to-fetch/host "^/" ]
to-insert: rejoin [ "GET " to-fetch/as-string/from-path-only "
HTTP/1.0^/Host: " to-fetch/host "^/" ]
foreach [key value] header-block [
append to-insert rejoin [ key ": " value "^/" ]
]
append to-insert "^/"
port: open/lines [
scheme: 'tcp
host: to-fetch/host
port-id: 80
]
print "[Vi sender:]"
print form to-insert
insert port to-insert
header: make block! 10
while [ not empty? reply: first port ] [
parse reply [
[copy name [thru #":"] (name: load name) | copy name [to end] (print
form name)]
[copy value to newline | copy value to end] (if value [append header
reduce [name value]])
]
]
either [ not empty? content: first port ] [content: copy port] [print
EMPTY!
]
close port
reduce [header content]
]
a: fetch-url http://www.rebol.com/
print mold first a
print "^/^/===^/^/"
;print second a
halt
; END OF SCRIPT
HY