Created
September 26, 2010 09:49
-
-
Save kiwanami/597782 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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