0👍
It seems that Beego only accepts data with this header: 'Content-Type': 'multipart/form-data'
so after I added that header everything was ok.
Since I didn’t know how to do that with axios
I switched to vue-resource
and this is the example code which works with Beego:
this.$http.post("/", {test: "test"}, {
emulateJSON: true
});
Now you can print it like this:
fmt.Println(this.GetString("test"))
I hope this helps someone
0👍
Just verified that axios and vue-resource use application/json
by default. The emulateJSON
you use here tells vue-resource to use application/x-www-form-urlencoded
. You probably just need to do a json decode in beego because it by default treats request body as urlencoded
.
multipart/form-data
works probably because it’s been there for long(like urlencoded
) so beego by default recognizes it. To use vue-resource to post a multipart/form-data
request: use FormData. Axios also accepts a FormData as data
.