From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: How to send a request to a Website.
Date: Thu, 20 Apr 2017 07:54:36 -0700 [thread overview]
Message-ID: <87fuh386z7.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 2320801.DznD1DNTWb@e6430
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.
next prev parent reply other threads:[~2017-04-20 14:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-20 10:59 How to send a request to a Website Thierry Leurent
2017-04-20 14:54 ` Eric Abrahamsen [this message]
2017-04-20 17:02 ` Thierry Leurent
2017-04-20 17:24 ` Eric Abrahamsen
2017-04-20 18:07 ` Thierry Leurent
2017-04-20 18:15 ` Kevin Buchs
2017-04-20 21:22 ` Thierry Leurent
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fuh386z7.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).