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: Thierry Leurent
Subject: Re: How to send a request to a Website.
Date: Thu, 20 Apr 2017 19:02:08 +0200
User-agent: KMail/5.2.3 (Linux/4.9.0-2-amd64; KDE/5.28.0; x86_64; ; )

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 <address@hidden> 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




reply via email to

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