HarmonyOS 鸿蒙Next:如何将包含数组和对象的JSON字符串拼接为表单类型的字符串(application/x-www-form-urlencoded)
HarmonyOS 鸿蒙Next:如何将包含数组和对象的JSON字符串拼接为表单类型的字符串(application/x-www-form-urlencoded)
{
“osType”: “harmonyos”,
“appM5”: “cccccccccccccccccc”,
“version”: “v1.0.0”,
“appId”: “xxxxxxxxxxxxxxxxxxxx”,
“fontSize”: “middle”,
“account”: “hz”,
“password”: “123”,
“loginType”: “0”,
“user”: {
“name”: “cc”,
“age”: “18”
}
}
http发送请求时,接口采用的是表单的提交方式,请问大佬们如何将类似于上述的json字符串拼接成表单格式再提交。重点是有些json中包含数组和对象
3 回复
当前可使用axios三方库重写transformRequest方法进行替代,可参考demo如下:
axios.post(this.url, formData, {
headers: { 'Content-Type': 'multipart/form-data' },
transformRequest:(data:Object)=>{
return data
}
})