I have a problem with passing data to Vuejs post
method. I'm using vue-resource and in documentation is:
this.$http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
I want to put header and it works fine(server reads header correct) for:
this.$http.post(
'http://localhost:8081/login',
{
headers: {
'Accept': 'application/json'
}
});
but if I try add any data something goes wrong, for example I tried:
this.$http.post(
'http://localhost:8081/login',
{username: 'admin'},
{
headers: {
'Accept': 'application/json'
}
});
or define some data and put there like:
this.$http.post(
'http://localhost:8081/login',
this.data,
{
headers: {
'Accept': 'application/json'
}
});
and for both solutions body section is always empty - check body data from request by using:
body = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
Probably problem is in vue.js code ebcause it works fine it I send any request from Postman. What should I do?
VueJS props are the simplest way to share data between components. Props are custom attributes that we can give to a component. Then, in our template, we can give those attributes values and — BAM — we're passing data from a parent to a child component!
Vue Fetch data from API exampleconst responsePromise = fetch(resourceUrl [, options]); The Response object we mention above represents the entire HTTP response, it does not directly contain the response body. To get the actual JSON body of the response, we use response. json() method.
Have you tried sending a post request without including the third argument with post
this.$http.post('url', {something: "string"})
.then ((res)=> console.log (res.body))
.catch ((error)=> console.log(error))
This works for me...
Another thing, are you sure you're getting the request data properly in the back end... it seems like python and I'm not totally sure how it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With