javascript - axios post请求提交后抛出431错误
问题描述
我有一个单页项目,我想提交表单,但是当我的 axios 请求尝试运行时收到 431(请求标头字段太大)错误。不知道还有什么可以尝试的,所以如果有人有任何建议,那就太好了!
我尝试过的事情:
set maxContentLength and maxBodyLength to Infinity,
added max-http-header-size
配置在哪里:
axios({
method: 'post',
url: 'http://example.com',
params: {a:b},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function (response) {
console.log(response)
}).catch(function (error) {
console.log(error)
})
当参数内容长度很小时,它可以工作。
但是,当参数内容长度太大(如 14kb)时,它会收到 431 错误(请求标头字段太大)
完整的 URL 如下所示:
http://localhost:9527/console/article/update?id=24321&title=%E5%8F%82%E4%B8%8E%E6%A0%87%E9%A2%9819000000061&image[]=&browseNumber=0&likeNum=1&shareNum=0&type=2&aspectType=0&status=1&userId=21334&admin=LZ000001&descStr=%E5%8F%82%E4%B8%8E%E5%86%85%E5%AE%B919000000061&roof=0&commodityIds[]=41&examine=1&htmlUrl=http:%2F%2Flocalhost:8080%2Fstatic%2Fhtml%2Fatlas%2B24321.html&isDel=0&sortNum=0&sortNo=0&createTime=2020-11-04+12:04:10&activityId=3&userNickName=iVQH4763&article=%3Cp%3E%E5%8F%82%E4%B8%8E%E5%86%85%E5%AE%B919000000061%3C%2Fp%3E&isLike=0&labelIds[]=8
我想这个错误是由于url的参数内容太大引起的。而且我想不出正确配置的方法。任何帮助将不胜感激。谢谢!
解决方案
尝试这样做:
axios.post('http://example.com',
{
a:b
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
推荐阅读
- vmware - 在 AMD Ryzen 5 3500 上尝试 ESXi 6 / 6.5 时发现错误“无网络适配器”
- gcc - 测量全局变量的内存使用情况
- html - 我不知道如何将图像放在边框内
- python - 两条迹线,但只有一条由滑块控制
- python - Python 时间已过不准确显示
- python - 我们是否期望基线(所有特征)和选定特征对决策树执行相同的操作?
- python - 如何在多个 CSV 文件上使用 describe() 并使用 CSV 文件名保存到一个文件中
- java - 导出使用 postgresql 的 javaFx 项目后出现问题
- java - JavaFX XYChart.Series - 无法在数据点上设置特定颜色/大小
- swagger - 我可以分离出组合模式并在 OpenAPI 中引用它吗?