tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

url-retrieve POST data encoding #185

Closed nivekuil closed 4 years ago

nivekuil commented 4 years ago

url-retrieve seems to expect its POST data (and likely other fields) to be properly encoded beforehand. Otherwise, it throws a Multibyte text in HTTP request error.

So in order to handle sending utf-8 data like “fancy quotes”, I have to pass :data like so:

(request "http://localhost:8080/query"
      :type "POST"
      :data (if (multibyte-string-p query) (encode-coding-string query 'utf-8) query)
...

Likewise to get the data of the response in the success callback, I have to do:

(decode-coding-string (request-response-data response) 'utf-8))

or else that fancy quote just looks like \342\200\234.

I think this should be handled in request.el, or at least documented as a gotcha.

dickmao commented 4 years ago

I see what you mean.

If the four-year-old discussion surrounding Bug#23750 (are you Leo Liu's brother?) wasn't going to make a judgment call about multibyte handling (and just begs off with an error) then I'd rather the humble abstraction of request.el remain similarly noncommital.