● 发起 HTTPS 网络请求request
分类:发起请求
是否支持H5:支持
参数
Object object
| 参数名 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| url | string | 是 | 开发者服务器接口地址 | |
| data | string/object/ArrayBuffer | 否 | 请求的参数 | |
| header | Object | 否 | 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json | |
| method | string | GET | 否 | HTTP 请求方法 |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(接口调用成功、失败都会执行) |
object.success 回调函数
参数
Object res
| 属性 | 类型 | 说明 |
|---|---|---|
| data | string/Object/Arraybuffer | 开发者服务器返回的数据 |
| statusCode | number | 开发者服务器返回的 HTTP 状态码 |
调用示例
原生
const _data = {
url: 'https://open-develop-stg1.paic.com.cn/searchContent',
method: 'post',
data: {
searchStr: '保障'
},
header: {
'Content-Type': 'application/json;charset=UTF-8'
}
}
wx.request({
..._data,
success(res) {
console.log(res)
},
fail(error) {
reject(error);
},
});
H5
const _data = {
url: 'https://open-develop-stg1.paic.com.cn/searchContent',
method: 'post',
data: {
searchStr: '保障'
},
header: {
'Content-Type': 'application/json;charset=UTF-8'
}
}
PAMINA.call('request', _data, res => {
console.log(res)
}, e => {
console.log(e)
})