Skip to content

Instantly share code, notes, and snippets.

@kiwanami
Created September 26, 2010 09:49
Show Gist options
  • Save kiwanami/597782 to your computer and use it in GitHub Desktop.
Save kiwanami/597782 to your computer and use it in GitHub Desktop.
;; HTTP POST by url-retrieve
;; ref: http://www.emacswiki.org/emacs/UrlPackage
(defun deferred:url-retrieve-post (url args &optional cbargs)
(lexical-let ((nd (deferred:new))
(url url) (args args)
(cbargs cbargs)
buf)
(deferred:next
(lambda (x)
(let ((url-request-method "POST")
(url-request-extra-headers
'(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data
(mapconcat
(lambda (arg)
(concat (url-hexify-string (car arg))
"="
(url-hexify-string (cdr arg))))
args
"&")))
(setq buf
(url-retrieve
url
(lambda (xx) (deferred:post-task nd 'ok buf))
cbargs)))
nil))
nd))
(deferred:$
(deferred:url-retrieve-post
"http://127.0.0.1:8080/post-test.cgi"
'(("a" . "test") ("param" . "OK")))
(deferred:nextc it
(lambda (buf)
(insert (with-current-buffer buf (buffer-string)))
(kill-buffer buf))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment