Vue Resource Post Request Content-Type

Request to send a Vue resource:

this.$http.post(form.action, new FormData(form)).then(function (response) {
    FetchResponse.fetch(this, response.data)
})

The request is sent as Content-Type: "application / json; charset = utf-8" But the PHP Post data is not displayed.

Setting Vue Resource Header:

request.headers.set ('Content-Type', '');

But Request Content-Type: ", multipart / form-data; border = ---- WebKitFormBoundaryTsrUACAFB1wuhFOR"

There is a comma at the beginning of the request.

JQuery email query:

$.ajax({
    url     : form.action,
    type    : 'POST',
    data    : new FormData(form),
    success : function (reqData) {
        FetchResponse.fetch(ss, reqData)
    },
});

The same query works without jQuery problems. jQuery Content-Type: "multipart / form-data; border = ---- WebKitFormBoundaryTsrUACAFB1wuhFOR"

Question: https://github.com/vuejs/vue-resource/issues/398

+4
1

JSON vue-resource 'emulateJSON':

const formData = {
    someProp: this.someProp,
    someValue: 'some value'
};

this.$http.post(this.postUrl, formData, {emulateJSON: true})
   .then(response => {
        console.log(response.body);
    }, response => {
       console.error(response.body);
    });
+2

Source: https://habr.com/ru/post/1654290/


All Articles