tkf / emacs-request

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

Example does not work without curl #175

Open egh opened 4 years ago

egh commented 4 years ago

Versions: Ubuntu 18.04 GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16

Steps to reproduce:

  1. Retrieve request.el: wget https://raw.githubusercontent.com/tkf/emacs-request/master/request.el
  2. Open emacs -Q
  3. M-x load-library json
  4. Open request.el and eval buffer
  5. Eval: (setq request-backend 'url-retrieve)
  6. Eval:
    (request
    "http://httpbin.org/put"
    :type "PUT"
    :data (json-encode '(("key" . "値1") ("key2" . "値2")))
    :headers '(("Content-Type" . "application/json"))
    :parser 'json-read
    :encoding 'utf-8
    :success (cl-function
           (lambda (&key data &allow-other-keys)
             (message "I sent: %S" (assoc-default 'json data)))))

Expected result: Message I sent: ((key . "値1") (key2 . "値2"))

Actual result: error:

Contacting host: httpbin.org:80
#s(request-response nil nil nil nil nil "http://httpbin.org/put" nil (:type "PUT" :data "{\"key\":\"値1\",\"key2\":\"値2\"}" :headers (("Content-Type" . "application/json")) :parser json-read :encoding utf-8 :success (lambda (&rest --cl-rest--) "

(fn &key DATA &allow-other-keys)" (let* ... ...)) ...) #<buffer  *http httpbin.org:80*> nil nil ...)
url-http-create-request: Multibyte text in HTTP request: PUT /put HTTP/1.1
MIME-Version: 1.0
Connection: keep-alive
Extension: Security/Digest Security/SSL
Host: httpbin.org
Accept-encoding: gzip
Accept: */*
User-Agent: URL/Emacs Emacs/26.3 (X11; x86_64-pc-linux-gnu)
Content-Type: application/json
Content-length: 24

{"key":"値1","key2":"値2"}
jcs090218 commented 1 year ago

I have the same issue as well. 😕

kiennq commented 2 weeks ago

To answer this question, you will need to encode data with utf8 encoding before send it over with url-retrieve. (encode-coding-string (json-encode '(("key" . "値1") ("key2" . "値2"))) 'utf8 'nocopy)