help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to send a request to a Website.


From: Eric Abrahamsen
Subject: Re: How to send a request to a Website.
Date: Thu, 20 Apr 2017 07:54:36 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Thierry Leurent <thierry.leurent@asgardian.be> writes:


[...]

> Emacs' Code ---------------
> (require 'url)
> (require 'url-http)
> (require 'json)
> (defvar user-data
>   (with-current-buffer
>       (progn
>       (url-request-method        "POST")
>       (url-request-extra-headers `(("Content-Type" . "application/x-www-form-
> urlencoded")
>                                    ("Authorization" . "bearer 
> 1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt")))
>       (url-request-data          (json-encode '(:title "Post using emacs.")))
>       (url-retrieve-synchronously 
> "https://asgardian.be/WordPress/wp-json/wp/v2/
> posts?state=1234&access_token=1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt")
>       )

I'm surprised the above doesn't raise an error: first of all you're also
missing the "buffer" argument to `with-current-buffer'. Then the `progn'
form evaluates each of the forms it contains individually, meaning that
something like (url-request-method "POST") would be seen as a function
call to `url-request-method', which isn't a real function, and should
raise an error. In your progn, the first three forms should be variable
bindings, only the last is an actual function call. So:

(with-current-buffer buffer-name
    (let ((url-request-method "POST")
          (url-request-extra-headers
           `(("Content-Type" . "application/x-www-form- urlencoded")
             ("Authorization" . "bearer 
1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt")))
          (url-request-data (json-encode '(:title "Post using emacs."))))
      (url-retrieve-synchronously "https://asgardian.be/WordPress/wp-json/wp/v2/
 posts?state=1234&access_token=1zzpkqkabx2v424kjn8yqmfjhywzny6sn2bmb7kt")))


Try that and see if it works.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]