Beego不接受Ajax参数

I'm trying to make simple POST request using VueJS to an application which is written in Beego framework (GoLang) but the application doesn't see any input request. Everything is ok when I use standard form request (no ajax). This is my VueJS code:

storePost: function(event) {
    axios.post("/api/posts/store", {body: "test"}).then(function(response) {
        if (response.data.status == 200) {
            this.posts.push(response.data.data);
        }else {
            console.log("error");
        }
    }, function(response){
        console.log("error");
    });
}

and this is my Beego code:

// router.go
beego.Router("/api/posts/store", &controllers_API.PostsController{}, "post:Store")

// PostsController.go
func (this *PostsController) Store() {
    fmt.Println(this.GetString("body"))

    // some irrelevant code which handles the response...
}

fmt.Println always prints nothing. When I use standard forms fmt.Println prints the value of the body with no problems.

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

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.