SakamonWeb
New
Tools
Index
Edit
Unix/emacs/elisp
<<< http get request >>> 8< (defun url-http-get (url arg) "GET Request." (let ( (response-string nil) (url-request-method "GET") (url-request-data (mapconcat (lambda (arg) (concat (url-hexify-string (car arg)) "=" (url-hexify-string (cdr arg)))) args "&"))) (switch-to-buffer (url-retrieve-synchronously (concat url "?" url-request-data))) (goto-char (point-min)) (re-search-forward "\n\n") (setq response-string (buffer-substring-no-properties (point) (point-max))) (kill-buffer (current-buffer)) response-string)) (url-http-get "http://example.com/get.php" '(("hoge" . "fuga") ("piyo" . "1"))) ;; => "[{\"hoge\":\"fuga\"},{\"piyo\":\"1\"}]" >8 <<< http post request >>> 8< (defun url-http-post (url args) "POST request." (let ( (response-string nil) (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 "&"))) (switch-to-buffer (url-retrieve-synchronously url)) (goto-char (point-min)) (re-search-forward "\n\n") (setq response-string (buffer-substring-no-properties (point) (point-max))) (kill-buffer (current-buffer)) response-string)) (url-http-post "http://example.com/post.php" '(("hoge" . "fuga") ("piyo" . "1"))) ;; => "[{\"hoge\":\"fuga\"},{\"piyo\":\"1\"}]" >8
Sign:
freeze
sage
Attachment
New:
Sign:
Rename
Title:
Sign: