From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: How to send a request to a Website. Date: Thu, 20 Apr 2017 07:54:36 -0700 Message-ID: <87fuh386z7.fsf@ericabrahamsen.net> References: <2320801.DznD1DNTWb@e6430> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1492700145 30868 195.159.176.226 (20 Apr 2017 14:55:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Apr 2017 14:55:45 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 20 16:55:36 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DUa-0007j6-38 for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Apr 2017 16:55:32 +0200 Original-Received: from localhost ([::1]:54455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1DUf-0005eS-TZ for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Apr 2017 10:55:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1DUE-0005bv-4G for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 10:55:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1DUA-000371-5j for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 10:55:10 -0400 Original-Received: from [195.159.176.226] (port=56473 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1DU9-00036H-Ul for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 10:55:06 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1d1DU0-0006vU-8R for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 16:54:56 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 41 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:iyOHUQmip0/hAK+NT7zFCjv9atM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112820 Archived-At: Thierry Leurent 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.