【发布时间】:2021-10-09 09:53:28
【问题描述】:
我正在使用 Vue.js、axios 和 Spring。
在页面上我有以下 axios 代码
axios({
method: 'post',
url: '/user/info',
params: {
'_csrf' : document.getElementById('csrf_id').value,
'name' : 'job',
'age' : '25',
},
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'}
});
在服务器上我有这样的接收方法
@Controller
@RequestMapping("/user")
public class UserInfo {
@ResponseBody
@PostMapping(value = "/info", consumes = "application/x-www-form-urlencoded", produces = "application/json" + ";charset=utf8")
public String info(@RequestParam(value = "name") String name, @RequestParam(value = "age") String age) {
System.out.println(name);
System.out.println(age);
return "ok";
}
}
Axios 向服务器发出请求,但服务器返回 415 响应。 请求标头缺少 application/x-www-form-urlencoded 内容类型。我怀疑问题就出在这上面。
告诉我,我做错了什么?
【问题讨论】:
标签: java spring spring-mvc axios