Retrieve body from a HTTP request in Emacs

Often we’ll send a HTTP request in Emacs with url package, but how to just get the body from this request ?

According to Dealing with HTTP documents in Emacs URL manual, you can use Emacs MIME library to do that, in this way:

  1. Retrieve a URL with either url-retrieve-synchronously or url-retrieve. This will return a buffer.
  2. Dissect the buffer with mm-dissect-buffer. You MUST use with-current-buffer because mm-dissect-buffer only dissects the current buffer. This will return a list of MIME handles.
    • Always pass non-nil value to no-strict-mime because the message doesn’t have a MIME-Version header.
  3. Get the buffer of the handle with mm-handle-buffer.

That’s all ! You can deal with this buffer in any ways.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理