博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot oauth2 fetch 关于跨域请求的问题
阅读量:6970 次
发布时间:2019-06-27

本文共 1359 字,大约阅读时间需要 4 分钟。

hot3.png

客户端使用 fetch 发送 ajax 请求,一直出现401错误,一直认为是服务器端跨域设置问题,后来发现是客户端发送参数不对,

此方式不对,一直返回401

fetch('http://localhost:8080/oauth/token', {  method: 'POST',  model: 'cros',  headers: {    'Accept': 'application/json',    'Content-Type': 'application/json'  },  body: JSON.stringify({    'grant_type': 'password',    'scope': 'select',    'client_id': 'client',    'client_secret': 'client-ppp',    'username': 'zhangsan',    'password': '123456'  })})  .then(function (response) {    console.log('==================1===============')    console.log(response)  })  .catch(function (error) {    console.log('==================2===============')    console.log(error)  })

下面这种可以正常发送参数

let formData = new FormData()// 请求参数 ('key',value)formData.append('grant_type', 'password')formData.append('scope', 'select')formData.append('client_id', 'client')formData.append('client_secret', 'client-ppp')formData.append('username', 'zhangsan')formData.append('password', '123456')fetch('http://localhost:8080/oauth/token', {  method: 'POST',  model: 'cros',  headers: {    'Accept': 'application/json'  },  body: formData})  .then(function (response) {    console.log('==================1===============')    console.log(response)  })  .catch(function (error) {    console.log('==================2===============')    console.log(error)  })

转载于:https://my.oschina.net/alyouge/blog/2873707

你可能感兴趣的文章
Nginx if 条件判断
查看>>
联想y460 +centos6.4 64位 开启无线热点Ap
查看>>
Htc t528w root教程
查看>>
Python 标准库中的装饰器
查看>>
Linux下查看和添加环境变量
查看>>
spark2.x由浅入深深到底系列六之RDD java api详解四
查看>>
jmeter+ant+jenkins
查看>>
Linux基础命令---grep
查看>>
Linux基础命令---cancel取消打印任务
查看>>
理解ORACLE数据库字符集
查看>>
Top Coder算法题目浏览器
查看>>
为SharePoint 2016 配置SQL 2016的always on 模式(二)
查看>>
PHP 选择排序法
查看>>
使用css3做立体效果!
查看>>
CIO的管理经
查看>>
ssh故障解决一例
查看>>
linux学习笔记-第十一课-shell基础
查看>>
当Ctrl+Alt+Del失效时,你需要用net user 来改密码
查看>>
C++的变量作用域
查看>>
ES搭建
查看>>