HttpGet

If you really want to know how HTML and HTTP work, or if you are debugging some HTTP problems, the following might come handy. It is also good to have if you need to get data from the web, but you don’t need to render it. Ideal for web services.

See also HttpPost, RFC 2616. Not entirely loosely related is HtmlRendering.

The original code was written by PatrickAnderson for the EmacsWebBrowser; it is now heavily modified by AlexSchroeder.

Current?

Be aware that emacs since v22 has included the UrlPackage. It lets you do HTTP GET, POST, OPTIONS, HEAD, accept cookies, do authentication, use proxies, and so on. Very thorough. Works great in emacs v23. Therefore this code may be redundant and out of date.

Changes

Questions

I use it on GNU Emacs 21.2.92.1 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2003-01-19 on confusibombus (the pretest), and on a GNU Emacs 21.1 for Windows at work. – AlexSchroeder

It appears to not be compatible with XEmacs 21.1 as it tries to set-process-coding-system. – DavidMasterson

Yes, it uses the coding system unix, but it seems that binary works just as well and also exists on XEmacs. I also improved debugging so you can use http-get-debug to disable all filtering and seing the command being sent to the server. – AlexSchroeder


A little wrapper for the http-get function that creates a file for the buffer and does http-decode-buffer. Useful for downloading source code.

    (defun http-find-file-sentinel (proc message)
      (switch-to-buffer (process-buffer proc))
      (http-decode-buffer)
      (set-visited-file-name (concat "/tmp/" buffer-name)))
    (defun http-find-file (url)
      (interactive "sURL: ")
      (setq splitted-url (split-string url "/"))
      (setq buffer-name (first (last splitted-url)))
      (http-get url nil 'http-find-file-sentinel nil buffer-name nil))

I need advice about getting a workable simple-wiki setup under winXP. I can’t have any buffer filled with the data :( All I know is that the proxy I am currently behind is a MS product (NTLM fucking technology) and that I have to “fake” it using an alternate proxy running locally. I have set the good options to tell simple-wiki to use my own proxy and response get properly back but apart from that nothing is etting back on my emacs buffer. Anyone has any clue on that ? I am really frustrated with this as I have to do all wiki edition under Mozilla and so I am susceptible to be caught by my boss :) So I need it to be done under Emacs (which nobody knows here ;)) – XavierMaillard

Well try to use something like (http-get-debug “http://whatever.org/” nil 1.1) and (http-get-debug “http://whatever.org/” nil 1.0) to see if you get some responses. What do you mean by response get back properly ? Also can you please specify the intermediate proxy you are using? I’ve take a look at the protocol [1] and there is no chance to implement it without being able to test it. Also we might move this discussion to HttpGet or SimpleWikiEditMode page. (I also set up a mailing list on savannah for http-emacs but I’m the only subscriber at this time :-)) – PierreGaston
I have finally achieved what I wanted after 2 days of heavy RTFM’ing :). You can see the details (not final explanation) on my wiki page XavierMaillard.

Emacs-Web

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

Simple example:

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

(require 'web)

(let ((query-data (make-hash-table :test 'equal)))
  (puthash 'name "nic" query-data)
  (puthash 'email "nic@example.com" query-data)
  (web-http-get
    (lambda (con header data)
      (with-current-buffer (get-buffer-create "*httpbuf*")
         (erase-buffer)
         (insert data)
         (switch-to-buffer (current-buffer))))
    "http://localhost:8001/someplace"
    :data query-data))

Getting Emacs-Web

It’s available from marmalade here.


See also: SimpleWikiEditMode, HttpPost, HttpGetWin32


CategoryHypermedia CategoryInterface