javascript - Vue,在 Vue JS 中向服务器发送带有标头配置的 GET 请求
问题描述
当在 vue js 组件中创建组件时,我想向具有以下标头的服务器发送 GET 请求:
我应该如何写这个请求?
卷曲:
-X GET "http://134.140.154.121:7075/rest/api/Time" -H "accept: application/json" -H "授权:承载 eyJhbGciOiJSUzI1NiIsImtpZCI6IkFZd21VU0Jvd2lxcVRSRG81NTctVFEiLCJ0eXAiOiJhdCtqd3QifQ.yywyw"
它发送的信息如下:
回复正文:
{“值”:{“值”:“字符串”}}
如何随请求一起发送标头和输出设置?
解决方案
fetch("http://134.140.154.121:7075/rest/api/Time",{
method:'GET',
header:{
'accept': 'application/json',
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IkFZd21VU0Jvd2lxcVRSRG81NTctVFEiLCJ0eXAiOiJhdCtqd3QifQ.eyJuYmYiOjE1OTMfryyw'
}
})
.then(res => res.json())
.then(res => {
// Use res
}
推荐阅读
- rest - 有没有办法增加 Google Directions API 中允许的最大航点数?
- r - 将 WAV 文件转换为 Txt 数据集
- scala - Scala:递归匹配案例?
- javascript - 反应私有路由无限渲染 - 出现错误错误:超过最大更新深度
- azure - 找不到具有 AssemblyQualifiedName、URI 或 FriendlyName ''trx' 的测试记录器
- javascript - 将 React-router 从 4 升级到 5
- algorithm - 关于 alpha-beta 修剪的 Minimax 问题?
- python - 如何按布尔值过滤?
- python - 为什么我的文件的最后修改时间戳是 1980 年 1 月 1 日?
- r - 将 VBA 函数翻译成 R