by shigemk2

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

manual request.el post

manual request.el post

マルチバイト文字列データのJSON POST

(request-deftest request-post-multibytes ()
  (request-testing-with-response-slots
      (request-testing-sync "report/some-path"
                            :type "POST"
                            :data '(("鍵" . "値"))
                            :parser (lambda ()
                                      (let ((json-key-type 'string))
                                        (json-read))))

普通のJSON POST これでマルチバイト文字列を投げるとjson-encodeがうまくいかなくて失敗する

(request
 "http://httpbin.org/put"
 :type "PUT"
 :data (json-encode '(("key" . "value") ("key2" . "value2")))
 :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)))))

http://tkf.github.io/emacs-request/manual.html