Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got the impression that <code>url.el</code> 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 and <code>url.el</code> will query the user for user name and password.</p> <p>You can have a look at my code on <a href="http://github.com/hdurer/fluiddb.el/" rel="noreferrer">http://github.com/hdurer/fluiddb.el</a> where I try to do things programmatically.</p> <p>Basically, I create the HTTP authorzation header myself (base64 encoding the correctly formatted string and adding the correct header to <code>url-request-extra-headers</code>). Then in a second step I need to add advice to <code>url-http-handle-authentication</code> so that it won't ask the user should the passed credentials not be acceptable.</p> <p>This feels a lot like raping <code>url.el</code> but it works for me and is the only way I could make it work.</p> <hr> <p>Your code would thus look something like this:</p> <pre><code> (defvar xyz-user-name "admin") (defvar xyz-password "admin") (defvar xyz-block-authorisation nil "Flag whether to block url.el's usual interactive authorisation procedure") (defadvice url-http-handle-authentication (around xyz-fix) (unless xyz-block-authorisation ad-do-it)) (ad-activate 'url-http-handle-authentication) (defun login-show-posts () (interactive) (let ((xyz-block-authorisation t) (url-request-method "GET") (url-request-extra-headers `(("Content-Type" . "application/xml") ("Authorization" . ,(concat "Basic " (base64-encode-string (concat xyz-user-name ":" xyz-password))))))) (url-retrieve "http://localhost:3000/essay/1.xml" (lambda (status) (switch-to-buffer (current-buffer)) )))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload