I am encountering an issue with passing data to the Vue.js post
method. I am using vue-resource and according to the documentation, it should be structured like this:
this.$http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
When I try to add a header, everything works smoothly (the server reads the header correctly) for example:
this.$http.post(
'http://localhost:8081/login',
{
headers: {
'Accept': 'application/json'
}
});
However, when I attempt to include any data, things start going wrong. For instance, I tried:
this.$http.post(
'http://localhost:8081/login',
{username: 'admin'},
{
headers: {
'Accept': 'application/json'
}
});
Or defining some data and including it like this:
this.$http.post(
'http://localhost:8081/login',
this.data,
{
headers: {
'Accept': 'application/json'
}
});
In both cases, the body section is always empty - I checked the body data from the request using:
body = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
The issue probably lies within the vue.js code as sending requests from Postman works without any problems. What steps should I take to resolve this?