javascript - 使用 React 发出 HTTP POST 请求
问题描述
你如何从以下 React 发出 POST 请求:
http --auth name:password POST http://localhost:5000/api/tokens
我目前使用 React 提出请求的尝试如下:
const requestOptions = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'name',
password: 'password'
})
};
fetch('/api/tokens', requestOptions).then(res => res.json());
谢谢
解决方案
推荐阅读
- bash - 无法获取分配给变量的多个命令(由 PIPE 分隔)的退出状态
- vue.js - vue js mutli vselect不允许从下拉列表中重复选择
- c# - 可以用空值初始化 WeakReference 吗?
- android - 在 Kotlin 中,一个 Handler 线程会等待另一个线程完成吗?
- graphql - 使用 GraphQL 进行微服务互通有意义吗?
- c++ - VC++ wcsftime (strftime) 不返回带有 %x 的正确语言环境字符串
- linux-kernel - 了解调度和 /proc/[pid]/sched
- angular - 使用多选组件在 Select 中设置默认选中项
- xamarin.ios - 如何为所有受支持的 iOS/Android 尺寸创建应用程序图标?
- twilio - 作为频道管理员在 Twilio 上的可编程聊天中加入频道,以在消息中发送媒体