DWQA QuestionsCategory: ServerHow to use Axios post? When a large amount of data is transmitted, 413 FULL head appears.
King asked 6 days ago

Publish articles using axios, code as follows:

this.$axios({
    method: 'post',
    url: '/post',
    data: {
        description: opt.editorContent,
        time: time,
        ...
    },
})
.then(res => {
    ...
}

The request sent is in JSON format and cannot be retrieved by the background routine mode, and 413 FULL head error is reported when the description data is overwritten
Manual changeContent-TypeIt doesn’t work either.

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
3 Answers
Best Answer
King answered 6 days ago

To update:
Just saw an ultimate solution in SF

// HTTP request interceptor
axios.interceptors.request.use(
  config => {
    if (config.method === 'post' || config.method === 'put') {
      config.data = qs.stringify(config.data)
      // config. headers ['Content-Type']='application/x-www-form-urlencoded'can be unconfigured and automatically recognized
    }
    return config
  },
  err => {
    return Promise.reject(err)
  })

==================
This problem has been stuck for a day, Baidu and Google have searched for it, and there are also some information in issue.qs.stringifyBut they all use aliases:

axios.post('http://something.com/', querystring.stringify({ foo: 'bar' }));

Record solutions:
As a matter of fact, post should be used.['Content-Type'] = 'application/x-www-form-urlencoded'The way is right… Why is it still JSON type?
Previously post was usedparamsParametric passing, resulting in the same change as get requestsURL parametersFollowing in the URL causes the URL to be too long.413 FULL headWrong Report
I like to write Axios configuratively, where posts need to betransformRequestOnly when it is processed can it be identified asx-www-form-urlencodedtype

this.$axios({
    method: 'post',
    url: '/post',
    data: {
        description: opt.editorContent,
        time: time,
        ...
    },
    transformRequest: [function (data, headers) {
        console.log(headers)
        return qs.stringify(data)
    }],
})
.then(res => {
    ...
}
Locker replied 6 days ago

In the react environment, config. headers [‘Content-Type’] need to be turned on, otherwise the data will not be received.

yeachen answered 6 days ago

Ha-ha, I just used Axios when I met, jq’s AJAX is the default application/x-www-form-urlencoded, that is, has been encrypted, but Axios is not.

Anterior small white de fossa answered 6 days ago

Thanks for sharing and learning, but I have never met this problem.