javascript - 使用 React 获取 cURL 请求
问题描述
我有一个 GET curl 请求
curl -X GET "http://localhost:8000/get/folder" -H "accept: application/json" -H "path: /"
解决方案
像这样的东西应该工作。
fetch('http://localhost:8090/get/directory', {
headers: {
'Accept': 'application/json',
'Path': '/',
}
})
.then(response => response.json())
.then(json => console.log(json));
例如,你可以useEffect()
在你的 React 应用程序中调用它。或者componentDidMount
如果它是一个类组件。
推荐阅读
- wcf - entlib wcf 集成在尝试通过引用传递参数时抛出异常
- chef-infra - 当在配方中设置 ENV 时,厨师警告设置密钥
- android - MqttException (0) - javax.net.ssl.SSLHandshakeException:使用 MQTTAndroid 客户端握手失败
- ios - Apple Mail(iOS 中的应用程序)中的链接不起作用
- node.js - 如何在此方法之外使用 body 的值?
- sublimetext3 - SublimeText 即时设置设置
- reactjs - 通过用户搜索处理从列表中排除项目的最佳方法是什么?
- angular - Angular 在返回时重新加载整个应用程序 (location.back)
- python - HDf5 数据维度从 (512,1080) 更改为 (512,1080,1)
- ios - 根据按下的按钮,通过 Segue 传递变量返回的对象