9

我正在尝试从我的 elisp 代码发送一个 HTTP GET 请求,并将响应的内容存储在一个变量中。简单到

use LWP::Simple;
my $data = get("http://some.url");

我使用 Windows 7 和 Emacs 24.2。


我尝试使用Emacs-Web包。这基本上是文档中的一个示例,更加简化:

(web-http-get
 (lambda (httpc header my-data)
   (message my-data))
 :url "http://breqwas.net/test.txt"))

这不起作用,我在 minibuffer 中得到这个响应:

Keyword argument http://breqwas.net/emacs.txt not one of (:host :port :extra-headers :mode :logging)

文档中的原始代码以同样的方式失败。


我还查看了http-get函数,但是“在缓冲区中获取 URL”——这不是我需要的。我不需要它在缓冲区中,我需要它在变量中。

4

1 回答 1

14

我建议使用url-retrieve-synchronouslyEmacs 附带的。结果被放置在缓冲区中,但您可以轻松地将其评估为字符串,如下所示:

(with-current-buffer (url-retrieve-synchronously "http://stackoverflow.com")
  (prog1
      (buffer-string)
    (kill-buffer)))
于 2013-05-08T18:13:00.013 回答