I'm trying to do a post request to a server with form-data but I can't get it to work. When I do it with postman it works, but with the $http.post it's not working. Any idea how to solve the problem?
All post data is send as application/json by default, if you want to send as form-data can enable this option:
Vue.http.options.emulateJSON = true;
:+1:
Hi guys,
this default behavior is weird. Many frameworks try to parse POST request to pairs as key=value. Sending JSON issues unexpected errors.
Yeah,I also think the default behavior is werid,and there is no info warn user that.
I added this to the docs, see https://github.com/vuejs/vue-resource/blob/master/docs/config.md
Thanks, but I do still think 99% users enabled emulateJSON param so it should be default. But the docs should solve the mystery when you ask google what to do.
But I want to use multipart/form-data not application/x-www-form-urlencoded.
Is there any settings I can do?
I've just faced same problem.
Solved with "emulateJSON" flag in options.
let options = {
emulateJSON: true
};
this.$http.post(url, postObj, options)
the this.$http.put(url, formData) don't work, with post work, why?
Use post with Vue.http.options.emulateJSON = true;
doing all above methods still sends a url with empty parameters
Most helpful comment
All post data is send as application/json by default, if you want to send as form-data can enable this option: