HTTP: Difference between revisions

217 bytes added ,  2 years ago
Emacs Lisp: Improve solution, add asynchronous version
m (→‎{{header|Raku}}: Remove unnecessary and deprecated pragma)
(Emacs Lisp: Improve solution, add asynchronous version)
Line 1,066:
 
=={{header|Emacs Lisp}}==
<code>url.el</code> can download HTTP. <code>url-retrieve-synchronously</code> returns a buffer containing headers and body. Caller kills the buffer when no longer required.
 
{libheader|url.el}}
<lang Lisp>(with-current-buffer
<code>url.el</code> can download HTTP. <code>url-retrieve-synchronously</code> returns a buffer containing headers and body. Caller killsmust kill the buffer when no longer requiredneeded.
(url-retrieve-synchronously "http://www.rosettacode.org")
 
(goto-char (point-min))
<lang Lisp>(let ((buffer (url-retrieve-synchronously "http://www.rosettacode.org")))
(search-forward "\n\n" nil t) ;; skip headers
(unwind-protect
(prin1 (buffer-substring (point) (point-max)))
(kill-buffer (with-current-buffer)))</lang> buffer
(prin1message "%s" (buffer-substring (point)url-http-end-of-headers (point-max))))
(kill-buffer buffer)))</lang>
 
Asynchronously (buffer doesn't need to be killed by caller):
 
<lang Lisp>(url-retrieve "http://www.rosettacode.org"
(lambda (_status)
(message "%s" (buffer-substring url-http-end-of-headers (point-max)))))</lang>
 
=={{header|Erlang}}==
Anonymous user