The code on this page is ideal for web services, where you need to interface to the web, but you don’t really need HTML rendering. Just as HttpGet makes HTTP GET requests, the code on this page makes HTTP POST requests.

Different methods for doing HTTP POSTS

See also HttpGet.

Url package

The UrlPackage which is now part of Emacs, provides support for authentication and cookies and can do POST requests, for example:

        (let ((url-request-method        "POST")
	      (url-request-extra-headers `(("Content-Type" . "application/x-www-form-urlencoded")))
	      (url-request-data          "field1=Hello&field2=from&field3=Emacs"))
	  (with-current-buffer (url-retrieve-synchronously url)


DennyZhang says: I like Lisp:http-post-simple.el very much.

I also have made some enhancement: insert the HTTP output in a configurable buffer, instead of mixed in \*Message\* buffer.

Since I can’t contact with the original author (Tom Schutzer-Weissmann), I post my enhancement here.

  (defun http-post-simple (url fields &optional charset bufname)
    "Send FIELDS to URL as an HTTP POST request, returning the response
   and response headers.
   FIELDS is an alist, eg ((field-name . \"value\")); all values
   need to be strings, and they are encoded using CHARSET,
   which defaults to 'utf-8"
    (let (request-result)
      (setq request-result (http-post-simple-internal
                            (http-post-encode-fields fields charset)
      ;; set buffername
      (unless bufname (setq bufname
                            (format "*HTTP POST %s *" url)))
        (delete-other-windows) ;; bury other window
        (split-window-vertically) ;; split window vertically
        ;; switch to window for HTTP output
        (pop-to-buffer (get-buffer-create bufname))
        (insert (mapconcat '(lambda(x)
                              (if (integerp x)
                                  (int-to-string x)
                                (identity x)))
                           (nreverse request-result) "\n"))


Emacs-Web is an attempt to make a simple HTTP client library for EmacsLisp.

Simple example:

;; -*- lexical-binding: t -*-

(require 'web)

(defun my-web-post-done (result)
   (message "the web post is done! %S" result))

(let ((query-data (make-hash-table :test 'equal)))
  (puthash 'name "nic" query-data)
  (puthash 'email "" query-data)
    (lambda (con header data)
      (my-web-post-done data))
    :data query-data))

Getting Emacs-Web

It’s available from marmalade here.

CategoryInterface CategoryHypermedia