我在离子3项目中增加了插件
$ ionic cordova plugin add cordova-plugin-advanced-http
$ npm install --save @ionic-native/http@4我想在本地HTTP请求中传递FormDate。
var formData = new FormData();
formData.append('file', fileObject)
formData.append('temp_id', '');
let headers = {
"Accept": "application/json",
"api-auth": 'apiAuthToken String',
"User-Auth": 'userAuthToken String'
}
this.http_native.setDataSerializer('urlencoded');
this.http_native.setHeader('*', 'Content-Type', 'application/x-www-form-urlencoded');
this.http_native.post('url String', formData, headers).then(api_response => {
});错误:advanced-http: "data" argument supports only the following data types: Object
发布于 2019-09-04 12:54:52
您需要在post方法的第二个参数中传递一个对象。当您设置-url时,对象将自动转换为格式url编码-
this.http_native.setDataSerializer('urlencoded');移除:
var formData = new FormData();
formData.append('file', fileObject)
formData.append('temp_id', '');代之以:
var formData = {
file: fileObject,
temp_id: ''
}最后提出邮寄请求:
let headers = {
"Accept": "application/json",
"api-auth": 'apiAuthToken String',
"User-Auth": 'userAuthToken String'
}
this.http_native.setDataSerializer('urlencoded');
this.http_native.setHeader('*', 'Content-Type', 'application/x-www-form-urlencoded');
this.http_native.post('url String', formData, headers).then(api_response => {
});如果您想上传文件,那么检查这个文档- https://github.com/silkimen/cordova-plugin-advanced-http#uploadfile
https://stackoverflow.com/questions/57773574
复制相似问题