HWH5.fetchVPN
HWH5.uploadFileVPN
HWH5.downloadFileVPN


HWH5.fetchVPN

支持版本>=10.1.2

发起网络请求

请求参数

参数 类型 必填 说明
url String 接口url
method String 服务请求类型,仅支持 get / post / put / delete
body String 请求参数
headers Object 请求头
timeout Number 超时时间

返回说明

服务端自定义

请求示例

get请求

  • ES6版本

    const _url = 'http://xxxx:8080/wecode/getData';
    const _headers = {
      'Content-Type': 'application/json'
    };
    
    HWH5.fetchVPN(_url, { method: 'get', headers: _headers, timeout: 6000 }).then(res => res.json()).then(reply => {
      console.log('服务端返回: ', reply);
    }).catch(error => {
      console.log('请求异常', error);
    });
    
  • ES5版本

    var _url = 'http://xxxx:8080/wecode/getData';
    var _headers = {
      'Content-Type': 'application/json'
    };
    
    HWH5.fetchVPN(_url, { method: 'get', headers: _headers, timeout: 6000 }).then(function (res) {
      return res.json();
    }).then(function (reply) {
      console.log('服务端返回: ', reply);
    }).catch(function (error) {
      console.log('请求异常', error);
    });
    

post请求

  • ES6版本
  const _url = 'http://xxxx:8080/wecode/getData';
  const _headers = {
    'Content-Type': 'application/json'
  };

  const _params = {
    'param1': 'xxx',
    'param2': 'xxx'
  };

  HWH5.fetchVPN(_url, { method: 'post', body: JSON.stringify(_params), headers: _headers }).then((res)=>res.json()).then((reply)=>{
    console.log('服务端返回: ', reply);
  }).catch((error)=>{
    console.log('请求异常', error);
  });
  • ES5版本

    var _url = 'http://xxxx:8080/wecode/getData';
    
    var _headers = {
      'Content-Type': 'application/json'
    };
    
    var _params = {
      'param1': 'xxx',
      'param2': 'xxx'
    };
    
    HWH5.fetchVPN(_url, { method: 'post', body: JSON.stringify(_params), headers: _headers }).then(function (res) {
      return res.json();
    }).then(function (reply) {
      console.log('服务端返回: ', reply);
    }).catch(function (error) {
      console.log('请求异常', error);
    });
    

HWH5.uploadFileVPN

支持版本>=10.1.2

上传文件

请求参数

参数 类型 必填 说明
serverUrl String 服务器地址,绝对路径
formData Object 自定义body中的其他数据,json结构。注意:无数据时,需传空值 {}
filePath String 文件存放到本地的地址,包含文件名称及后缀
zip Bool true:压缩后传,false:不压缩上传
name String 开发者在服务器端通过该key可以获取到文件二进制内容
headers Object 自定义的header信息
progress Number 是否返回上传进度。1:返回,0:不返回。默认为 0
onProgress Function 当progress为1时,必填。回调函数,持续回调

返回结果

无。

请求示例

  • ES6示例

    HWH5.uploadFileVPN({
      zip: false,
      serverUrl: 'http://example.com/uploadFile', // 示例地址,非真实服务,需要配置云桥
      filePath: 'xxx.jpg',
      name: 'file',
      headers: {},
      formData: { capKey: 'xxxxxx.xxxxxx', audioFormat: 'pcm16k16bit' },
      progress: 1,
      onProgress: (_data) => {
        console.log(_data, '~~~data');
      }
    }).then(data => {
      console.log('服务端返回数据:', data);
    }).catch(error => {
      console.log('HWH5.uploadFileVPN上传异常', error);
    });
    
  • ES5示例

    HWH5.uploadFileVPN({
      zip: false,
      serverUrl: 'http://example.com/uploadFile', // 示例地址,非真实服务
      filePath,
      name: 'file',
      headers: {},
      formData: {},
      progress: 1,
      onProgress: function (_data) {
        console.log(_data, '~~~data');
      }
    }).then(function (data) {
      console.log('服务端返回数据:', data);
    }).catch(function (error) {
      console.log('HWH5.uploadFileVPN上传异常', error);
    });
    

HWH5.downloadFileVPN

支持版本>=10.1.2

文件下载

请求参数

参数 类型 必填 说明
url String 下载资源的url
headers Object Object HTTP请求Header
filePath String 文件存放到本地的地址,包含文件名称及后缀(/download/test.png)

返回结果

参数 说明
status 下载成功:1

请求示例

  • ES6版本

    HWH5.downloadFileVPN({
      url: '',
      headers: {},
      filePath: ''
    }).then(result => {
      console.log(result);
    }).catch(error => {
      console.log('下载异常', error);
    });
    
  • ES5版本

    HWH5.downloadFileVPN({
      url: '',
      headers: {},
      filePath: ''
    }).then(function (result) {
      console.log(result);
    }).catch(function (error) {
      console.log('下载异常', error);
    });
    

结果。 ""

    无结果。 ""