【问题标题】:getting info from fetch function从 fetch 函数中获取信息
【发布时间】:2022-07-18 20:53:56
【问题描述】:

我正在寻找一种方法来使用从 fetch 函数获得的响应作为字符串,关于如何实现它的任何想法?

这里是获取函数:

const fetch = require("node-fetch");
var myHeaders = new fetch.Headers();
myHeaders.append("apikey", "that's where my API key is");

var requestOptions = {
 method: 'GET',
 redirect: 'follow',
 headers: myHeaders
};

fetch("https://api.apilayer.com/fixer/timeseries?base=BTC&symbols=ILS&start_date=2021-01-01&end_date=2021-12-31", requestOptions)
  .then(response => response.text())
  .catch(error => console.log('error', error));

【问题讨论】:

    标签: javascript node.js reactjs express


    【解决方案1】:

    你必须把你的逻辑放在上面提到的 then 块中

    fetch("https://api.apilayer.com/fixer/timeseries?base=BTC&symbols=ILS&start_date=2021-01-01&end_date=2021-12-31", requestOptions)
      .then(response => response.text())
      .then((res) => {
         //This is the block where you have to use the data
         console.log(res);
      })
      .catch(error => console.log('error', error));
    

    【讨论】:

      猜你喜欢
      • 2020-07-13
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 2021-01-06
      • 2021-07-18
      • 2012-10-31
      相关资源
      最近更新 更多