ajax - 在 ASP.Net Core 中将不记名令牌添加到 ajax POST 请求
问题描述
我有一个用ASP.Net Core 中的属性/Home/PostRequest
装饰的 POST 方法。[Authorize]
客户端我有一个经过身份验证的用户。我想构造一个 ajax POST 请求来调用该方法,但我不确定将什么放入 Authorization 标头中。身份验证凭据缓存在哪里,以什么形式缓存?
$.ajax({
type: "POST",
url: "/Home/PostRequest",
data: JSON.stringify(request),
headers: {
"Authorization": "** what to put here? **"
}
contentType: "application/json",
dataType: "json",
crossDomain: false,
success: function (response) {
successCallback(response);
},
failure: function (response) {
console.log("Failed");
},
error: function (xhr, response, thrownError) {
console.log("Error");
}
});
解决方案
推荐阅读
- java - 如何在 Spring Boot 中使用 @Valid 验证对象?
- javascript - 使用父/子路由文件的奇怪行为
- android - 在 gradle 构建工具之外运行 Android 单元测试 - 使用 java junit 命令行?
- sql - REGEXP_SUBSTR - 如何“避免”字符串中的括号
- reactjs - 使用 React 17 版本时无法要求图像
- android - 如何在 Android 中设置像 spotify 这样的 Instagram 故事?(我想与应用程序 url 分享图像作为故事)
- javascript - 我可以使用 sparkpost 发送 .ics 文件吗?(node.js)
- ios - 在 iOS Swift 上进行公钥固定时的 ASN1 标头
- amazon-quicksight - 让读者能够将过滤器集保存为书签
- mockito - 如何通过 Mockito.mockStatic(SpringUtils.class) 模拟 SpringUtils.getBean("beanName")