D
D
Darkness2019-07-22 20:27:42
JavaScript
Darkness, 2019-07-22 20:27:42

How to send a request to forismatic?

Actually , here is the API, but no matter how I try to make a request, it either gives out 404, or Method wronghelp me make the right request, I don’t even know what I’m doing wrong

fetch('https://cors-anywhere.herokuapp.com/http://api.forismatic.com/api/1.0/method=getQuote&format=xml&lang=ru',{
        method: 'post'
    })
    .then((data)=> {
        console.log(data)
    })
    
    .catch(function(error) {
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-07-22
@AntonBrock

using the chrome console and this site, I collected a not very obvious request - the parameters must be passed as a STRING in the body
https://api.forismatic.com/api/tester/

b = await fetch('https://cors-anywhere.herokuapp.com/https://api.forismatic.com/api/1.0/',
  {
    "headers":{"content-type":"application/x-www-form-urlencoded"},
    "body":"method=getQuote&format=xml&key=&lang=",
    "method":"POST"
  })

await b.text()

/*
"<forismatic><quote>
<quoteText>Мыслитель движется вперед, лишь если он не спешит с выводами, пусть даже они кажутся ему очевидными.</quoteText>
<quoteAuthor>Альбер Камю</quoteAuthor>
<senderName></senderName><senderLink></senderLink><quoteLink>http://forismatic.com/ru/668d4e4d3c/</quoteLink></quote></forismatic>"
*/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question