upHttpModule 通用网络请求模块

模块概述

upHttpModule提供通过原生请求server接口的能力,可以避免H5前端直接请求server接口时跨域问题;提供资源的上传/下载功能。


方法列表

  • get(get 请求)
  • post(post 请求)
  • uploadFile( uploadFile请求)
  • domainTransformToIP (域名转化为ip)
  • uploadFileWithProgress (上传文件带进度)
  • put(put请求)
  • delete(delete请求)
  • getCache (getCache请求)

公共数据

  • 请求公共参数模型OptionsInt

    {
    "url": "url",
    "data": {},
    "headers": {},
    "transform": true
    }
    
  • 请求公共参数模型定义

值类型 是否必填 说明
url String 请求路径
data Object 请求body
headers Object 请求header
transform boolean 是否启用域名转换为ip,true: 域名转换为ip false:不做转换(默认)
  • 上传请求模型FileOptionsInt

    {
    "url": "url",
    "data": {},
    "headers": {},
    "transform": true,
    "filePath": "string",
    "name": "string",
    }
    
  • 上传请求模型定义

值类型 是否必填 说明
url String 请求路径
data Object 请求body
headers Object 请求header
transform boolean 是否启用域名转换为ip,true: 域名转换为ip false:不做转换(默认)
filePath String 待上传的文件路径
name String 待上传的文件名称,可以不传
  • 上传(带进度)请求模型FileProgressOptionsInt

    {
    "url": "url",
    "data": {},
    "headers": {},
    "transform": true,
    "filePath": "string",
    "name": "string",
    "uploadId": "string",
    "progress": OnProgressListener,
    }
    
  • 上传(带进度)请求模型定义

值类型 是否必填 说明
url String 请求路径
data Object 传输的body
headers Object 接口所需headers,必须要传appId、appKey、accessToken、clientId、Content-Type,保持跟通用接口一样的数据
transform boolean 是否启用域名转换为ip,true: 域名转换为ip false:不做转换(默认)
filePath String 待上传的文件路径
name String 待上传的文件名称,可以不传
uploadId String 上传文件的id
progress callback 进度回调
  • 进度回调模型OnProgressListener

    export interface OnProgressListener {
    (progress: Object): void;
    }
    
  • 进度回调内容定义

值类型 说明
progress number 资源上传进度(0 ~ 100)
uploadId String 上传文件的id
  • get缓存请求模型OptionsCacheInt

    {
    "url": "string",
    "data": {},
    "headers": {},
    "transform": true,
    "useCache": "0",
    "getResponseCallback": callback,
    }
    
  • get缓存请求模型定义

值类型 是否必填 说明
url String 请求路径
data Object 请求body
headers Object 请求header
transform boolean 是否启用域名转换为ip,true: 域名转换为ip false:不做转换(默认)
useCache String 是否使用缓存,'1': 使用缓存 '0':不使用缓存
getResponseCallback callback 缓存回调
  • 所有数据均以JSON结构返回,由代码,信息和数据三部分组成

  • 服务器返回数据原样填充到data中

    {
      "retCode": "000000", //接口状态标识码
      "retInfo": "操作成功",//接口信息说明
      "retData": {
        "status": "200", //服务器状态标识码
        "headers": {...},//接口响应头信息
        "data": data,    //服务端返回的数据体,原样返回
      }
    }
    
  • 公共错误retCode说明:
retCode编码 retInfo说明
000000 操作成功
900000 操作失败
900003 非法参数错误
999999 未知错误

具体定义:返回数据通用

补充说明: 1.如果接口需要签名,请优先使用signRequest接口,如果signRequest不能使用,建议前后端统一入参的签名顺序。 2.如果入参中有时间戳,请使用string类型。


模块变更记录

  • V4.0.0 重构网络插件
  • V3.0.0

    删除get请求接口传入参数中的data参数
    删除head,uploadFile,downloadFile接口

  • V3.2.0

    重构http模块,修改返回数据结构体,按照{retCode:'',retInfo:'',retData:''}结构返回数据
    增加uploadFile接口
    增加get、post方法在出错情况下的错误码说明信息

  • V3.3.0 增加是否使用httpDns字段:只支持nebula容器 增加domainTransformToIP(域名转换)接口:只支持nebula容器 增加uploadFileWithProgress(上传文件带进度) 增加put、delete接口 增加getCache接口


方法说明

  • get (get 请求)

    get({params})
适用性
容器 Nebula
支持情况
APP版本 6.12.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options OptionsInt 见公共模型
错误返回 retCode说明:

参照通用reCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 服务器返回数据,网络访问出错时为具体错误信息描述
示例:
uplusapi.upHttpModule.get({
  url:'http://uhome.haier.net/',
  headers:{}
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • post (post 请求)

    post({params})
适用性
容器 Nebula
支持情况
APP版本 6.12.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options OptionsInt 见公共模型
错误返回 retCode说明:

参照通用reCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 服务器返回数据,网络访问出错时为具体错误信息描述
示例:
uplusapi.upHttpModule.post({
  url:'http://uhome.haier.net/',
  headers:{},
  data:{}
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • put (put 请求)

    put({params})
适用性
容器 Nebula
支持情况
APP版本 6.14.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options OptionsInt 见公共模型
错误返回 retCode说明:

参照通用reCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 服务器返回数据,网络访问出错时为具体错误信息描述
示例:
uplusapi.upHttpModule.put({
  url:'http://uhome.haier.net/',
  headers:{},
  data:{}
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • delete(delete 请求)

    delete({params})
适用性
容器 Nebula
支持情况
APP版本 6.14.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options OptionsInt 见公共模型
错误返回 retCode说明:

参照通用reCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 服务器返回数据,网络访问出错时为具体错误信息描述
示例:
uplusapi.upHttpModule.delete({
  url:'http://uhome.haier.net/',
  headers:{},
  data:{}
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • uploadFile (上传资源)

    uploadFile({params})
适用性
容器 Nebula
支持情况
APP版本 6.12.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options FileOptionsInt 见公共模型
错误返回 retCode说明:

参照通用reCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 服务器返回数据,网络访问出错时为具体错误信息描述
示例:
uplusapi.upHttpModule.uploadFile({
  url:'http://uhome.haier.net/',
  headers:{},
  data:{},
  filePath: 'fs://a.txt'
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • domainTransformToIP (域名转换IP)

    domainTransformToIP({params})
适用性
容器 Nebula
支持情况
APP版本 6.14.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
url String 需要转换的域名
错误返回 retCode说明:

参照通用retCode

retData说明:
属性名 说明
IP 转换完成后的ip地址,例如:10.1.1.10
示例:
uplusapi.upHttpModule.domainTransformToIP({
  url:'http://uhome.haier.net/'
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • uploadFileWithProgress (上传媒体文件)

    uploadFileWithProgress({params})
    适用性
容器 Nebula
支持情况
APP版本 6.14.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options FileProgressOptionsInt 见公共模型
错误返回 retCode说明:

参照通用retCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 服务器返回数据,网络访问出错时为具体错误信息描述
示例:
uplusapi.upHttpModule.uploadFileWithProgress({
   url:'https://zj.haier.net/scs/commons/v1/file/upload',
   data: {type:"1",sizeLim:"0"},
   headers:{},
   transform: 'true';
   filePath: 'fs://a.txt',
   name:'haier',
   uploadId:'1',
   progress: (res) => {
    console.log(res);
  }
}).then((result) => {
  console.log('result',result);
}).catch((err) =>{
  console.log('err',err);
});
  • getCache (getCache 请求)

    getCache({params})
适用性
容器 Nebula
支持情况
APP版本 6.12.0 及以上
params 输入参数:
属性名 数据类型 是否必填 说明
options OptionsCacheInt 见公共模型
错误返回 retCode说明:

参照通用reCode

retData说明:
属性名 说明
status 状态码;http错误时,为错误码信息,1为连接超时,5为其它错误
headers 响应头
data 从缓存中返回数据
示例:
uplusApi.upHttpModule.getCache({
  url: 'https://s.ehaier.com/search/commonLoadItemNew.html?pholder=1&productCateId=2729&provinceId=16&cityId=173&districtId=2450&streetId=12036596&fromType=1&memberId=&qs=isHotDesc&filterData=&pageIndex=3&pageSize=10',
  headers: {'Accept': 'application/json'},
  data: {},
  transform: false,
  useCache: '1',
  getResponseCallback,
}).then((res) => {
  alert(JSON.stringify(res));
  console.log('success:getCache', res); 
}).catch((err) => {
  alert(JSON.stringify(err));
});

function getResponseCallback(ret) {
  alert(JSON.stringify(ret));
}

results matching ""

    No results matching ""