问题
I have an application problem / x-www-form-urlencoded with my form.In fact, when I send the data (in json format), they are well recovered by the method that does it except that I have this error message in the browser:
There was an unexpected error (type=Unsupported Media Type, status=415). Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported
Here are my different codes:
Method that retrieves the data from the form and inserts it into the database:
@RequestMapping(value = "/insert",method = RequestMethod.POST, consumes="application/json")
public @ResponseBody void createType(@RequestBody Type type) {
typeService.createType(type);
}
HTML :
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="app">
<h1>TEST FORM</h1>
<form action="" method="post">
<p>Type description: <input type="text" v-model="type.description"/></p>
<p><button v-on:click="addType()"> Send </button><input type="reset" value="Reset" /></p>
</form>
</div>
<script src="http://cdn.jsdelivr.net/vue/1.0.10/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
Vue.prototype.$http = axios;
new Vue({
el:'#app',
data:{
type:{description:''}
},
methods:{
addType(){
let newType = {description:this.type.description};
console.log(newType);
this.$http.post('/types/insert',newType).then(response => {
console.log(response);
});
}
}
});
</script>
</body>
</html>
I tried the different enctype (text / plain, multipart / form-data and application / json; application / x-www-form-urlencoded being the default) of the form but none allowed me to solve the problem.
Thank you in advance.
来源:https://stackoverflow.com/questions/47990345/unsupported-media-type-status-415