Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example does not work without curl #175

Open
egh opened this issue Jan 19, 2020 · 2 comments
Open

Example does not work without curl #175

egh opened this issue Jan 19, 2020 · 2 comments

Comments

@egh
Copy link

egh commented Jan 19, 2020

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
Copy link

I have the same issue as well. 😕

@kiennq
Copy link
Contributor

kiennq commented Aug 31, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants