首页 > 解决方案 > 使用 React 获取 cURL 请求

问题描述

我有一个 GET curl 请求

curl -X GET "http://localhost:8000/get/folder" -H  "accept: application/json" -H  "path: /"

标签: javascripthtmlreactjscurl

解决方案


像这样的东西应该工作。

fetch('http://localhost:8090/get/directory', { 
  headers: {
    'Accept': 'application/json',
    'Path': '/',
  }
})
.then(response => response.json())
.then(json => console.log(json));

例如,你可以useEffect()在你的 React 应用程序中调用它。或者componentDidMount如果它是一个类组件。


推荐阅读