我得到的印象是url.el
大部分是專爲交互式操作,也就是你做一個呼叫未經授權,服務器以403「需要授權」響應(正確的代碼?)的地位和url.el
將查詢用戶名用戶和密碼。
你可以看看我的代碼http://github.com/hdurer/fluiddb.el,我嘗試以編程方式做事情。
基本上,我自己創建HTTP授權標頭(base64編碼格式正確的字符串並將正確的標頭添加到url-request-extra-headers
)。 然後在第二步中,我需要添加建議到url-http-handle-authentication
,以便它不會要求用戶輸入的憑證不可接受。
這感覺很像強姦url.el
但它適用於我,並且是我能使它工作的唯一方法。因此
您的代碼將是這個樣子:
(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))
))))
感謝您的評論。我已經閱讀了twit.el,twitter.el和mediawiki.el的資源,但是我還沒有弄清楚他們正在做什麼以進行身份驗證。我也會檢查你的。再次感謝! – wallyqs 2009-10-22 17:49:38
一個完全不同的解決方案可能是不使用url.el - 我只看了一下identica模式(就是google的模式),那裏的HTTP請求是完全手動組裝的。對我來說,這感覺有點像重新發明輪子。 – 2009-10-22 20:28:28
我使用的twiter模式(twit.el)不會以編程方式進行身份驗證,而是依賴於url.el - 即用戶會在第一次請求時詢問twitter的名稱和密碼。 – 2009-10-22 20:30:08