Vue-resource: Post as form-data

Created on 17 Jun 2015  路  11Comments  路  Source: pagekit/vue-resource

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?

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:

Vue.http.options.emulateJSON = true;

All 11 comments

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.

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

Was this page helpful?
0 / 5 - 0 ratings