请求配置
ucs-request 请求库的全局自定义配置项
配置项
osRequest
类型:
UTSJSONObject可选值:
| 值 | 类型 | 描述 | 默认值 | 兼容性 | 说明 |
|---|---|---|---|---|---|
| development | string | 测试环境-请求的前缀 | - | APP / Web / 微信小程序 / 支付宝小程序 / QQ小程序 / 快手小程序 | 不在兼容性范围的平台,将自动切换使用production 正式环境地址 |
| production | string | 正式环境-请求的前缀 | - | ||
| header | UTSJSONObject | 默认请求的 header | - | ||
| requestTimeout | number | 请求超时时间,单位 ms | 60000 | ||
| uploadFileTimeout | number | 上传超时时间,单位 ms | 120000 | ||
| downloadFileTimeout | number | 下载超时时间,单位 ms | 120000 | ||
| withCredentials | boolean | 跨域请求时是否携带凭证(cookies) | false | 微信小程序 / Web | |
| firstIpv4 | boolean | DNS解析时优先使用ipv4 | false | 微信小程序 | |
| enableChunked | boolean | 开启 transfer-encoding chunked。 | false |
使用演示
温馨提示
在标准基座 / 自定义基座 编译运行时请求库前缀拼接采用的是 development 测试环境地址,正式打包编译采用的则是 production 正式环境地址
例如开发者需要配置请求属性,则只需要设置 osRequest 配置
ts
// ucsDefineConfig.uts
import { defineConfig } from "@/uni_modules/ucs-config";
defineConfig({
// 配置项,需要哪项配置则配置哪项,这里作为演示则将所有配置项列出,开发者请根据实际需求配置
osRequest: {
// 测试环境
development: "https://xxxxx.com",
// 正式环境
production: "https://xxxxxx.com",
header: {
//自定义请求头信息,注意:值不能为中文字符,否则会报错
"custom-header" : "hello"
},
timeout: 60000,
withCredentials: false,
firstIpv4: false,
enableChunked: false
}
});