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.
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.
I use it on GNU Emacs 188.8.131.52 (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
;; -*- lexical-binding: t -*- (require 'web) (let ((query-data (make-hash-table :test 'equal))) (puthash 'name "nic" query-data) (puthash 'email "firstname.lastname@example.org" 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))
It’s available from marmalade here.