axios请求415错误Uncaught (in promise) Error: Request failed with status code 415
2020-01-12 18:48
1101 查看
Uncaught (in promise) Error: Request failed with status code 415
错误如下图
前端代码(vue):
var data = { username: this.loginForm.username, password: this.loginForm.password } this.$axios.post(this.GLOBAL.host + '/login', this.$qs.stringify(data) ).then(res => { // Determine the login status based on the returned results console.log(res) })
后台代码(springboot):
@Controller public class LoginController { @Autowired private LoginService loginService; @RequestMapping(value = "/login",method = RequestMethod.POST) @ResponseBody public Object login(@RequestBody UserDTO userDTO){ return loginService.login(userDTO.getUsername(),userDTO.getPassword()); } }
错误原因:
当我们使用application / x-www-form-urlencoded时,Spring并不将其理解为RequestBody。因此,如果我们想要使用它,我们必须删除@RequestBody注释。
然后尝试以下方法:
修改LoginController代码:
@Controller public class LoginController { @Autowired private LoginService loginService; @RequestMapping(value = "/login",method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = {MediaType.APPLICATION_ATOM_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) @ResponseBody public Object login(UserDTO userDTO){ return loginService.login(userDTO.getUsername(),userDTO.getPassword()); } }
重新试一下~~访问成功,问题解决啦
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- axios特别说明request failed with status code 404
- ubuntu 安装mysql 错误Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lmPxC
- Python使用pip install psycopg2安装psycopg2包出现python setup.py egg_info failed with error code 1 in /tmp/pip-build-YtLeN3/psycopg2错误处理
- Request failed with status code 522【IDEA创建SpringBoot无法连接的错误】
- python2.7 安装channels出现Command"python setup.py egg_info" failed with error code 1 in /tmp/pip-build-y
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- 解决XCode编译错误clang: error: linker command failed with exit code 1
- vps中docker启动出现错误Job for docker.service failed because the control process exited with error code. Se
- duplicate symbol _OBJC--clang: error: linker command failed with exit code 1 错误
- command "python setup.py egg_info" failed with error code 1 in ...
- 解决Qt5.5运行时,出现Error - RtlWerpReportException failed with status code :-1073741823.
- Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details
- Command "python setup.py egg_info" failed with error code 1 in ...
- 关于Python安装模块出现error: command 'gcc' failed with exit status 1错误的解决方法
- 安装MySQL-python-1.2.3c1出现“error: command 'gcc' failed with exit status 1”错误
- MAC pip安装包出现 Command "python setup.py egg_info" failed with error code 错误
- CentOs安装Scrapy出现error: Setup script exited with error: command ‘gcc’ failed with exit status 1错误解决方案
- error:Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/_r/fcrtlb8
- 解决XCode编译错误clang: error: linker command failed with exit code 1
- 有关Error - RtlWerpReportException failed with status code :-1073741823.的解决方法