From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Thierry Leurent Newsgroups: gmane.emacs.help Subject: Re: How to send a request to a Website. Date: Thu, 20 Apr 2017 19:02:08 +0200 Message-ID: <2453198.OlclnZDYAl@e6430> References: <2320801.DznD1DNTWb@e6430> <87fuh386z7.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit X-Trace: blaine.gmane.org 1492707781 21922 195.159.176.226 (20 Apr 2017 17:03:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Apr 2017 17:03:01 +0000 (UTC) User-Agent: KMail/5.2.3 (Linux/4.9.0-2-amd64; KDE/5.28.0; x86_64; ; ) 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 19:02:47 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 1d1FTg-0005GK-AM for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Apr 2017 19:02:45 +0200 Original-Received: from localhost ([::1]:55166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1FTk-0006kW-FH for geh-help-gnu-emacs@m.gmane.org; Thu, 20 Apr 2017 13:02:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1FTJ-0006jp-UZ for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 13:02:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1FTC-0007Vh-IM for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 13:02:21 -0400 Original-Received: from 16.mo3.mail-out.ovh.net ([188.165.56.217]:35083) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1FTC-0007Un-CL for help-gnu-emacs@gnu.org; Thu, 20 Apr 2017 13:02:14 -0400 Original-Received: from player758.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo3.mail-out.ovh.net (Postfix) with ESMTP id 60A65C83A1 for ; Thu, 20 Apr 2017 19:02:12 +0200 (CEST) Original-Received: from e6430.localnet (200.27-200-80.adsl-dyn.isp.belgacom.be [80.200.27.200]) (Authenticated sender: thierry.leurent@asgardian.be) by player758.ha.ovh.net (Postfix) with ESMTPSA id 0A3632C0086 for ; Thu, 20 Apr 2017 19:02:11 +0200 (CEST) In-Reply-To: <87fuh386z7.fsf@ericabrahamsen.net> X-Ovh-Tracer-Id: 16831077710883468246 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeliedrfedvgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenuc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.56.217 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:112822 Archived-At: Thank you your help but it don't work. It's not a syntax problem. The code return a result. IMHO, it's a trouble with the content of the http request. I'm not an lisp programmer and I have some trouble to understand how the code work. On Thursday, April 20, 2017 7:54:36 AM CEST Eric Abrahamsen wrote: > 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. -- Thierry Leurent