代码如下
upload(){
var data = [{
"value": 27.1,
"iValue": 27.1,
"timepoint": "2020-05-29 16:22:34",
"deviceCode": "BAEC0000005118"
}];
var url = api.uploadUsertempUrl();
console.log(url)
anti.sendRequest({
url:url,
data: data,
method: "POST",
success(res) {
if (res.statusCode != 200) {
console.log("数据上传失败", JSON.stringify(res))
return
}
},
fail(res){
console.log('上传远程数据库失败',JSON.stringify(res))
},
complete(res){
console.log('上传远程数据库完成',JSON.stringify(res))
console.log("请求api:",api.uploadUsertempUrl())
}
})
}
// anti.sendRequest 是自己封装的请求方式,具体如下
function sendRequest(options){
const token = uni.getStorageSync(constants.TOKEN_KEY);
var header = {};
if (token == null || token == ""){
header = {
'Content-Type': 'application/json;charset=UTF-8'
}
} else {
header = {
'Content-Type': 'application/json;charset=UTF-8',
'Authorization': "Bearer "+token
}
}
if(options.method){
options.method = options.method.toUpperCase();//小写改为大写
}
uni.request({
url: options.url,
data: options.data,
header: header,
sslVerify: false,
method: options.method || "GET",
timeout: options.timeout || 30000,
dataType: options.dataType || 'json',
responseType: options.responseType || 'text',
success(res){
typeof options.success == "function" && options.success(res);
},
fail(res){
typeof options.fail == "function" && options.fail(res);
},
complete(res){
typeof options.complete == "function" && options.complete(res);
}
})
}
IOS执行结果如图
安卓平台可以正常运行并获得返回
BUG机型:IPHONE6
ISO版本:11.2.6
HBUILDER版本:2.6.16.20200424