by shigemk2

当面は技術的なことしか書かない

Multibyte text in HTTP request

url-http-create-request Multibyte text in HTTP request

Emacs25からurl-http-create-requestするとき、マルチバイト文字列データをリクエストしようとするとエラーになる

** The URL package now insists on sending only unibyte strings to server This means packages that use URL cannot bind 'url-request-data' to multibyte strings. If non-ASCII characters should be part of the URL payload, then 'url-request-data' should be encoded to become a unibyte string.

https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-08/msg00031.html

http://misohena.jp/blog/2016-10-27-problem-org2blog-multibyte-text.html

たとえばrequest.elで、こんなのを投げるとエラーになる。url-retrieveをバックエンドにしてrequestを投げると、 Multibyte text in HTTP request エラーがでる。

(setq request-backend 'url-retrieve)
  (request
   "http://httpbin.org/put"
   :type "PUT"
   :data (json-encode '(("key" . "値1") ("key2" . "値2")))
   :headers '(("Content-Type" . "application/json"))
   :parser 'json-read
   :success (cl-function
             (lambda (&key data &allow-other-keys)
               (message "I sent: %S" (assoc-default 'json data)))))