I have not seen a really good example on the web. How can I add authentication to a request like this:
(defun login-show-posts ()
(interactive)
(let ((url-request-method "GET")
(url-request-extra-headers '(("Content-Type" . "application/xml"))))
(url-retrieve "http://localhost:3000/essay/1.xml"
(lambda (status)
(switch-to-buffer (current-buffer))
))))
if for example, the user and pass is admin:admin?
With twit.el, there was a little farting around to make it work. Authentication info is stored inside of an alist. This a list is bound to the symbol in the variable
url-basic-auth-storage
.You could probably do something like this:
This will leave the users authentication info alone (if they have any). Upon retrospect that might have been the smarter way to go with twit.el.
I got the impression that
url.el
was designed mostly for interactive operations, i.e. you do a call without authorisation, the server responds with a 403 "authorization needed" (correct code?) status andurl.el
will query the user for user name and password.You can have a look at my code on http://github.com/hdurer/fluiddb.el where I try to do things programmatically.
Basically, I create the HTTP authorzation header myself (base64 encoding the correctly formatted string and adding the correct header to
url-request-extra-headers
). Then in a second step I need to add advice tourl-http-handle-authentication
so that it won't ask the user should the passed credentials not be acceptable.This feels a lot like raping
url.el
but it works for me and is the only way I could make it work.Your code would thus look something like this: