[Vuejs]-Vue.js not working, Error for "Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version."

1👍

Since i am lazy to find a way to adding token into vue resource function. Then i just change it to axios because it can avoid this error. So i just change

 this.$http.post('/create/post', { content:this.content })

to

 axios.post('/create/post', { content:this.content })

then it can solve the csrf-token problems. And i think this only work for laravel 5.4 because it is predefined.

0👍

The solution to this problem is attaching proper header in your request,
here is the proper post request with proper header, I have tested myself and it is working.

var config = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    responseType: 'blob'
 };

axios.post('/user', {}, config)
.then((response)=>{
    console.log(response)
}).catch((error)=>{
    console.log(error.response.data)
});

I hope the server will treat you well and not return the warning regarding HTTP_RAW_POST_DATA.

0👍

methods: {

    onSubmit(){

        var formData = this.toFormData(this.$data); 

        axios.post('/projects', formData)
        .then(response => alert("success"))
        .catch(error => alert("inv") );
    },

    toFormData: function(obj){
        var form_data = new FormData();
        for(var key in obj ){
            form_data.append(key, obj[key]);
        }
        return form_data;
    }

}

//im using laravel 5.4 vue js 2, no need for attaching proper header. just add the toFormData.

Leave a comment