Skip to content

请求配置

ucs-request 请求库的全局自定义配置项

配置项

osRequest

  • 类型:UTSJSONObject

  • 可选值:

类型描述默认值兼容性说明
developmentstring测试环境-请求的前缀-APP / Web / 微信小程序 / 支付宝小程序 / QQ小程序 / 快手小程序不在兼容性范围的平台,将自动切换使用production 正式环境地址
productionstring正式环境-请求的前缀-
headerUTSJSONObject默认请求的 header-
requestTimeoutnumber请求超时时间,单位 ms60000
uploadFileTimeoutnumber上传超时时间,单位 ms120000
downloadFileTimeoutnumber下载超时时间,单位 ms120000
withCredentialsboolean跨域请求时是否携带凭证(cookies)false微信小程序 / Web
firstIpv4booleanDNS解析时优先使用ipv4false微信小程序
enableChunkedboolean开启 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
	}
});