Skip to content

Instantly share code, notes, and snippets.

@kakakikikeke
Last active December 15, 2015 12:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakakikikeke/5262112 to your computer and use it in GitHub Desktop.
Save kakakikikeke/5262112 to your computer and use it in GitHub Desktop.
emacsでHTTP Requestを送信、取得するためのelispです。デフォルトemacsに入っている url パッケージを使っています。
(require 'url)
(defun send-http-request (url)
"Send a simple http request and open a result within an other buffer.."
(let
(
(url-request-method "GET")
(url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))))
(url-retrieve url 'switch-to-buffer-for-responce)))
(defun switch-to-buffer-for-responce (status)
(switch-to-buffer
(current-buffer)))
(defun get-response (url)
"Get the http response info."
(let
(
(url-request-method "GET")
(url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded")))
(buffer (url-retrieve-synchronously url)))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(concat (buffer-substring-no-properties (point) (point-max))) )))
(provide 'send-http-request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment