使用axios发布文章,代码如下:
this.$axios({
method: 'post',
url: '/post',
data: {
description: opt.editorContent,
time: time,
...
},
})
.then(res => {
...
}
发送的请求是json格式的,后台常规方式无法获取,而且当description数据过大会报413 FULL head错误
手动改Content-Type
也不起作用
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
更新:
刚刚在sf看到一个终极解决方案
==================
这个问题卡了一天了,百度谷歌都搜了一圈了,issue里也有一些信息(都使用了
qs.stringify
),但都使用了别名方式:记录下解决方法:
按道理,使用post方式,应该使用
['Content-Type'] = 'application/x-www-form-urlencoded'
方式才对。。。为什么还是json类型的。之前post一直是用
params
参数传递,导致和get请求一样,变成了URL parameters
跟在url里,导致了url太长,413 FULL head
报错了我喜欢使用配置的方式写axios,此时post需要在
transformRequest
里处理了,才能识别为x-www-form-urlencoded
类型