OK -
after all the progress made yesterday, being able to successfully read
HTTP Basic Auth pages, I'm still not satisfied. I thought it might be
nice to put together an 'object' to help manage this process. While I am
able to do the following:
files ["mysite/default.htm" "mysite/page2.htm"]
foreach file files [
print read [
scheme: 'http
user: "webuser"
pass: "letmein"
host: "127.0.0.1"
path: file
]
]
I thought it was kind of tedious to have to retype the whole read bracket
every time. So I figured I would make an object - and store the
"state" of the page I was interested in reading - and then use a readpage
function against the object to retrieve the page.
objSecurePage.r
-------------------------------------------------------------------------
REBOL [
Title: "Password Page Object"
Date: 26-Jan-2000
Purpose: "A script to fetch web page(s) that use basic authentication"
File: %objSecurePage.r
Notes: {
A Rebol Object to facilitate the reading of secure page
contents. A secure page in this sense, is one which
is protected by basic authentication. It can also be used
to retrieve any page from a web server.
}
]
http_object: make object! [
; Attributes.
protocol: 'http
username:
password:
hostaddr:
filepath:
pagedata:
; Member Functions.
get_vals: func [] [
make block! [
protocol
username
password
hostaddr
filepath
]
]
readpage: func [] [
pagedata: read [
scheme: protocol
user: username
pass: password
host: hostaddr
path: filepath
]
]
]
objPage: make http_object [
username: "webuser"
password: "letmein"
hostaddr: "127.0.0.1"
filepath: "mysite/default.htm"
]
print objPage/get_vals
objPage/readpage
;print objPage/pagedata
-------------------------------------------------------------------------
So - I create a base object - which has no values other than the fact that
it's using the http protocol (scheme). It has two functions - one which
returns the block of values, the other reads the page - and sets the
member variable (attribute) to the contents of the page.
However - upon execution I get the following error:
-------------------------------------------------------------------------
>> do %objSecurePage.r
Script: "Password Page Object" (25-Jan-2000)
http webuser letmein 127.0.0.1 mysite/default.htm
** Access Error: Invalid port spec: scheme protocol user username pass
password host hostaddr
path filepath.
** Where: pagedata: read [
scheme: protocol
user: username
pass: password
host: hostaddr
path: filepath
]
>>
-------------------------------------------------------------------------
Why are the attributes of the object not evaluating? It seems to be
attempting to use the literal word. I have tried using the following code
in place of the read page routine -
-------------------------------------------------------------------------
readpage: func [] [
pagedata: read [
scheme: self/protocol
user: self/username
pass: self/password
host: self/hostaddr
path: self/filepath
]
]
-------------------------------------------------------------------------
But that results in an exception and the Rebol application crashes on my
NT system. What am I not understanding about referencing member variables
within an object?
Thanks,
Porter Woodward