更新时间:2022-12-29 GMT+08:00
分享

发起网络请求

请求参数

参数

类型

必填

说明

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

分享:

    相关文档

    相关产品