以下是我的elisp代码(凭证显然是假的):
(defvar assembla-username "foo")
(defvar assembla-password "bar")
(defvar tickets-url "http://www.assembla.com/spaces/aWx7Oas2352cwqjQWU/tickets/")
(defvar assembla-auth-header (concat "Basic " (base64-encode-string (concat assembla-username ":" assembla-password))))
; curl -H "Accept: application/xml" -u "foo:bar" http://www.assembla.com/spaces/aWx7Oas2352cwqjQWU/tickets/
(defun get-tickets()
(interactive)
(let ((url-request-extra-headers
'(("Accept" . "application/xml")
("Authorization" . assembla-auth-header)))))
(url-retrieve tickets-url (lambda (status)
(switch-to-buffer (current-buffer)))))
基于监视传出请求标头,未设置“Accept”标头。我很确定这是将我重定向到登录页面的内容,因为curl请求注释完全正常并且设置了Accept标头。
话虽这么说,有什么特别是我做错了,和/或是否有更好的包装在elisp中进行大量的REST调用?
谢谢!
答案 0 :(得分:1)
您没有评估assembla-auth-header
变量,而是在url-retrieve
之外致电let
,此时url-request-headers
已恢复到原始状态。您似乎也可能需要使用url-mime-accept-string
而不是将其添加到额外的标头中。
(defun get-tickets()
(interactive)
(let ((url-mime-accept-string "application/xml")
(url-request-extra-headers
`(("Authorization" . ,assembla-auth-header))))
(url-retrieve tickets-url (lambda (status)
(switch-to-buffer (current-buffer))))))
我建议尝试这样的事情,看看这是否至少正确地传递了 Accept 和 Authorization 标题。