标签:message ext 发送 scribe 后端 pos this ams log
在向后端请求时,如果上传的数据里存在file文件对象,需要用到表单提交,这时候我们需要将JSON对象,转成formData对象,具体见代码
const formData = new FormData(); Object.keys(params).forEach((key) => { formData.append(key, params[key]); });
下面也有可能需要formData转JSON,代码如下:
var jsonData = {};
formData.forEach((value, key) => jsonData[key] = value);
mypost1() {
let url = ‘http://1.1.1.1:8080/AA/pAA/kAAAin/quAA‘;
let params = {
AA: ‘‘,
SS: ‘‘,
DD: ‘1‘
}
const formData = new FormData();
Object.keys(params).forEach((key) => {
formData.append(key, params[key]);
});
console.log(formData)
this.http.post(url, formData).subscribe({
next: (res: any) => {
if (res.status === ‘success‘) {
} else { if (!res.message || res.message === ‘error‘) { this.msg.error(‘...‘) } else { this.msg.error(res.message); } }
}, error: (err: any) => { }
})
}
标签:message ext 发送 scribe 后端 pos this ams log
原文地址:https://www.cnblogs.com/sugartang/p/12163059.html