如何传特别长的字符串给后台服务器?(vue的axios+nodejs+express的情况下)
我现在需要传递一串特别长度的字符串给后台服务器,如图
{"c":1549473758948,"e":253402300799000,"v":"[{\"id\":1,\"fileName\":\"2016_Book_PsychometricFrameworkForModeli\",\"cover\":\"http://192.168.1.102:5070/img/Education/2016_Book_PsychometricFrameworkForModeli.jpeg\",\"title\":\"Psychometric Framework for Modeling Parental Involvement and Reading Literacy\",\"author\":\"Annemiek Punter, Cees A. W. Glas and Martina R. M. Meelissen\",\"publisher\":\"Springer International Publishing, Cham\",\"bookId\":\"2016_Book_PsychometricFrameworkForModeli\",\"category\":4,\"categoryText\":\"Education\",\"language\":\"en\",\"rootFile\":\"OEBPS/content.opf\",\"selected\":false,\"cache\":false,\"haveRead\":0,\"type\":1},{\"type\":4,\"cache\":true,\"selected\":false,\"fileName\":\"2013_Book_ManagingRiskAndInformationSecu\",\"title\":\"2013_Book_ManagingRiskAndInformationSecu\",\"id\":2},{\"id\":3,\"fileName\":\"2016_Book_SecondaryAnalysisOfElectronicH\",\"cover\":\"http://192.168.1.102:5070/img/MedicineAndPublicHealth/2016_Book_SecondaryAnalysisOfElectronicH.jpeg\",\"title\":\"Secondary Analysis of Electronic Health Records\",\"author\":\"MIT Critical Data\",\"publisher\":\"Springer International Publishing, Cham\",\"bookId\":\"2016_Book_SecondaryAnalysisOfElectronicH\",\"category\":17,\"categoryText\":\"MedicineAndPublicHealth\",\"language\":\"en\",\"rootFile\":\"OEBPS/content.opf\",\"selected\":false,\"cache\":false,\"haveRead\":0,\"type\":1},{\"type\":4,\"cache\":true,\"selected\":false,\"fileName\":\"2017_Book_IntelligentHumanComputerIntera\",\"title\":\"2017_Book_IntelligentHumanComputerIntera\",\"id\":4},{\"type\":4,\"cache\":true,\"selected\":false,\"fileName\":\"2018_Book_TheHuaweiAndSnowdenQuestions\",\"title\":\"2018_Book_TheHuaweiAndSnowdenQuestions\",\"id\":5},{\"id\":6,\"itemList\":[{\"id\":1,\"fileName\":\"2018_Book_DiseasesOfTheAbdomenAndPelvis2\",\"cover\":\"http://192.168.1.102:5070/img/MedicineAndPublicHealth/978-3-319-75019-4_CoverFigure.jpg\",\"title\":\"Diseases of the Abdomen and Pelvis 2018–2021\",\"author\":\"Juerg Hodler\",\"publisher\":\"Springer International Publishing\",\"bookId\":\"2018_Book_DiseasesOfTheAbdomenAndPelvis2\",\"category\":17,\"categoryText\":\"MedicineAndPublicHealth\",\"language\":\"en\",\"rootFile\":\"OEBPS/package.opf\",\"selected\":true,\"cache\":false,\"haveRead\":0,\"type\":1},{\"id\":2,\"fileName\":\"2016_Book_AHistoryOfRadionuclideStudiesI\",\"cover\":\"http://192.168.1.102:5070/img/MedicineAndPublicHealth/978-3-319-28624-2_CoverFigure.jpg\",\"title\":\"A History of Radionuclide Studies in the UK\",\"author\":\"Ralph McCready\",\"publisher\":\"Springer International Publishing\",\"bookId\":\"2016_Book_AHistoryOfRadionuclideStudiesI\",\"category\":17,\"categoryText\":\"MedicineAndPublicHealth\",\"language\":\"en\",\"rootFile\":\"OEBPS/package.opf\",\"selected\":true,\"cache\":false,\"haveRead\":0,\"type\":1},{\"id\":3,\"fileName\":\"2016_Book_PublicHealthEthicsCasesSpannin\",\"cover\":\"http://192.168.1.102:5070/img/MedicineAndPublicHealth/2016_Book_PublicHealthEthicsCasesSpannin.jpeg\",\"title\":\"Public Health Ethics: Cases Spanning the Globe\",\"author\":\"Drue H. Barrett, Leonard W. Ortmann, Angus Dawson, Carla Saenz, Andreas Reis and Gail Bolan\",\"publisher\":\"Springer International Publishing, Cham\",\"bookId\":\"2016_Book_PublicHealthEthicsCasesSpannin\",\"category\":17,\"categoryText\":\"MedicineAndPublicHealth\",\"language\":\"en\",\"rootFile\":\"OEBPS/content.opf\",\"selected\":true,\"cache\":false,\"haveRead\":0,\"type\":1}],\"selected\":false,\"title\":\"test\",\"type\":2},{\"id\":7,\"fileName\":\"2018_Book_SecurityInComputerAndInformati\",\"cover\":\"http://192.168.1.102:5070/img/ComputerScience/978-3-319-95189-8_CoverFigure.jpg\",\"title\":\"Security in Computer and Information Sciences\",\"author\":\"Erol Gelenbe\",\"publisher\":\"Springer International Publishing\",\"bookId\":\"2018_Book_SecurityInComputerAndInformati\",\"category\":1,\"categoryText\":\"ComputerScience\",\"language\":\"en\",\"rootFile\":\"OEBPS/package.opf\",\"selected\":false,\"cache\":false,\"haveRead\":0,\"type\":1},{\"id\":8,\"fileName\":\"2018_Book_ComplicationsAndQuandariesInTh\",\"cover\":\"http://192.168.1.102:5070/img/Laws/2018_Book_ComplicationsAndQuandariesInTh.jpeg\",\"title\":\"Complications and Quandaries in the ICT Sector\",\"author\":\"Ashish Bharadwaj, Vishwas H. Devaiah and Indranath Gupta\",\"publisher\":\"Springer Singapore, Singapore\",\"bookId\":\"2018_Book_ComplicationsAndQuandariesInTh\",\"category\":9,\"categoryText\":\"Laws\",\"language\":\"en\",\"rootFile\":\"OEBPS/content.opf\",\"selected\":false,\"cache\":false,\"haveRead\":0,\"type\":1},{\"id\":-1,\"type\":3}]"}
但是我传给后台之后打印出来只有半截的长度,然后显示undefined
axios代码:
export function localToServer(id, key, str) {
return axios({
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-=urlencoded;charset=UTF-8'
},
method: 'post',
url: `${process.env.VUE_APP_BASE_URL}/local`,
data: qs.stringify({
id: id,
[key]: str
})
})
}
localToServer(250, 'shelf', data)
.then(res => {
if (res && res.status === 200) {
console.log(res.data)
} else {
alert('客户端失败')
}
})
node代码:
app.post('/local', (req, res) => {
req.on('data', data => {
// 获取并解析post提交过来的数据
let formData = decodeURIComponent(data) // 转码
// let param = qs.parse(formData)
let param = querystring.parse(formData) // 转成object对象,方便使用
console.log(param.shelf)
})
})
之前查询了一些配置(没有用,依旧服务器端接受的数据打印出来只有半截...)
app.use(bodyParser.json({limit:'100mb'}));
app.use(bodyParser.urlencoded({ limit:'100mb', extended: true }));
不知道要如何解决啊?困扰了好久了QAQ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我自己建了个项目试了一下,数据能正常接收:
我暂时也找不到问题了,我把项目传到github上了,你拉了对比看一下吧。
https://github.com/MudOnTire/...
原答案已删除
post传输大小是没有限制的 get是有的
实在不行分片呗
使用 FormData 测试一下
使用 File 测试一下
观察 nodejs,看看是不是每次接受的都是同样的字节数。
观察 express 设置接受字节大小是否无效
还有为什么要打印出来?(不知道是不是这个问题。我觉得不是,不管是不是,这么做都是不对的!!!)
使用 IDE 看看字节数对不对
这个也没多长应该远远到不到被限制的大小
你对一下收到的request的body的size?可能控制台打印打不全而已吧