Error description
The front-end sending code is as follows
login() {
let {userCode, userPwd} = this.ruleForm;
// this.$axios.post('/UserInfoService/login',
// this.$qs.stringify({
// account: userCode,
// password: userPwd
// })).then(res => {
// console.log(res);
// })
this.$axios({
method: 'post',
url: '/UserInfoService/login',
data: {
account: userCode,
password: userPwd
}
}).then(res => {
console.log(res);
})
},
The content of the request body is as follows
{account: "111", password: "222"}
account: "111"
password: "222"
Whether the back end splits the attribute or uses the userinfo entity to receive it, it gets null
Cause of error
The reason is that the default sending data format of Axios is JSON format, not form data. As a result, the data passed to the back end is JSON format, and the back end cannot receive it directly. When the result is returned, the data sent by the front end will be passed to the front end
Solution
There are two solutions, as follows
The first is to change the format of the front-end transmission data to form data
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
But this method is not recommended, because the front-end and back-end communication uses the JSON format. The second method is to use the entity class to receive the parameters passed by the front-end, and use @ requestbody to modify the parameters
Read More:
- Nginx front end and back end separation + service cluster reverse proxy
- The time of the time database displayed by the front end is inconsistent
- Jsonformat annotation solves the problem of time format in the front end of localdatetime
- The solution of flashing back after the end of console program running
- Decipher the evolutionary path of junior, middle and senior programmers (front end)
- Front end Vue project operation error module build failed
- Nginx modifies the front end request size limit (413 request entity too large)
- Front end project construction error unexpected character ‘@’ solution
- Hide print button when printing page in front end
- What are the web front end technologies? What are the differences between cookie and session
- Record a front end error net:: err_ HTTP2_ PROTOCOL_ ERROR 200
- Record the pits you stepped on – NSS error – 5938 (PR_ END_ OF_ FILE_ ERROR), curl: (35) Encountered end of file
- Front end project runtime prompts syntax error: typeerror: token.type.endswith is not a function solution
- Solve the unexpected end of stream exception thrown by jedis
- Syntax error: unexpected end of file problem [two solutions]
- [Solved] Vue Error: TypeError: Cannot read property ‘end‘ of undefined
- control reaches end of non-void function
- error:control reaches end of non-void function [-Werror=return-type]
- On the problem that VTK + QT process can’t end after closing the program
- Split keyword in ABAP when the separator is at the beginning and end of the string