Using Http Authentication with VisualWorks
I recently (in 3.1) got Http authentication working in BottomFeeder. I didn't have to do anything out of the oridinary - all the support I need was already in the NetClients package, which has been part of the VW distribution for a few years now. So how do you add such support? Well, let's say you issue an Http request:
request := self fillRequestHeaders. client := HttpClient new. response := client executeRequest: request. response isUnauthorized ifTrue: [authInfo := self promptForAuthorization].
Now, once you have that authorization information, what do you do? Well, you create the request again, this time with the authorization information in it, then re-issue the request. Something like this:
request username: authInfo username password: authInfo password. response := client executeRequest: request.
That should do it. Now, of course, you'll want to catch exceptions, and handle other cases (movement of a page, various error responses, etc.). To get an idea of how to do that sort of thing, load the package Http-Access from the Public Store. The package handles authentication, moved pages, and mod-gzip automatically. I use it in BottomFeeder and my blog posting tools - it's getting real world use.
