【问题标题】:How can I handle HTTP request with react front-end and flask back-end如何使用反应前端和烧瓶后端处理 HTTP 请求
【发布时间】:2019-04-28 12:26:43
【问题描述】:

我正在为我的后端和前端的 react 使用烧瓶框架构建一个 Web 应用程序。我想使用http 请求连接这两个,但我不知道从哪里开始。我在前端和后端都使用 PyCharm IDE

我查看了react-http-request 库,但我不明白。

我希望能够将字符串从前端发送到后端,并将json 文件从后端发送到前端。

【问题讨论】:

  • 您可以使用axios。它是一个基于 Promise 的 HTTP 客户端,用于浏览器和 node.js。

标签: reactjs flask pycharm httprequest


【解决方案1】:

浏览器的原生 fetch() 函数可以为你做到这一点。

像这样使用它:

fetch('http://your.server.domain/api/endpoint', {
  method: 'GET',
  headers: {"Content-Type": "application/json"},
}).then((res) => {
  return res.json();
}).then((json) => {
  // this is your json data from your server
  console.log(json);
});

【讨论】:

    猜你喜欢
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 2020-04-06
    • 2019-05-11
    • 2019-07-17
    • 2021-07-11
    相关资源
    最近更新 更多