I'm trying to send an HTTP GET request from my elisp code and store the contents of the response in a variable. As simple as
use LWP::Simple;
my $data = get("http://some.url");
I use Windows 7 & Emacs 24.2.
I tried using Emacs-Web package. Here's basically an example from the documentation, simplified even more:
(web-http-get
(lambda (httpc header my-data)
(message my-data))
:url "http://breqwas.net/test.txt"))
That does not work, I get this response in minibuffer:
Keyword argument http://breqwas.net/emacs.txt not one of (:host :port :extra-headers :mode :logging)
The original piece of code from the documentation fails the same way.
I also looked at http-get function, but "get URL in a buffer" - that's not what I need. I don't need it in a buffer, I need it in a variable.
I'd recommend using url-retrieve-synchronously
that's included with Emacs. The results are placed in a buffer, but you can easily evaluate it as a string like so:
(with-current-buffer (url-retrieve-synchronously "http://stackoverflow.com")
(prog1
(buffer-string)
(kill-buffer)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With