Interface UniRequestBaseConfig

UniRequestBaseConfig 请求配置

interface UniRequestBaseConfig {
    baseUrl?: string;
    cloudCache?: boolean | object;
    complete?: ((result: GeneralCallbackResult) => void);
    data?: string | ArrayBuffer | AnyObject;
    dataType?: string;
    defer?: boolean;
    enableCache?: boolean;
    enableChunked?: boolean;
    enableCookie?: boolean;
    enableHttp2?: boolean;
    enableHttpDNS?: boolean;
    enableQuic?: boolean;
    fail?: ((result: GeneralCallbackResult) => void);
    firstIpv4?: boolean;
    forceCellularNetwork?: boolean;
    getResponse?: boolean;
    header?: any;
    httpDNSServiceId?: boolean;
    ignoreLoading?: boolean;
    method?:
        | "GET"
        | "POST"
        | "PUT"
        | "DELETE"
        | "HEAD"
        | "OPTIONS"
        | "TRACE"
        | "CONNECT";
    params?: any;
    responseType?: string;
    sslVerify?: boolean;
    success?: ((result: RequestSuccessCallbackResult) => void);
    timeout?: number;
    url?: string;
    withCredentials?: boolean;
}

Hierarchy

  • Partial<UniNamespace.RequestOptions>
    • UniRequestBaseConfig

Properties

baseUrl?: string

公共url

cloudCache?: boolean | object

是否开启云加速(详见云加速服务

complete?: ((result: GeneralCallbackResult) => void)

结束的回调函数(调用成功、失败都会执行)

data?: string | ArrayBuffer | AnyObject

请求的参数

dataType?: string

如果设为json,会尝试对返回的数据做一次 JSON.parse

defer?: boolean

控制当前请求是否延时至首屏内容渲染后发送

enableCache?: boolean

开启 cache

enableChunked?: boolean

开启 transfer-encoding chunked

enableCookie?: boolean

默认 false,开启后可在headers中编辑cookie(支付宝小程序10.2.33版本开始支持)

enableHttp2?: boolean

开启 http2

enableHttpDNS?: boolean

是否开启 HttpDNS 服务。如开启,需要同时填入 httpDNSServiceId 。 HttpDNS 用法详见 移动解析HttpDNS

enableQuic?: boolean

开启 quic

fail?: ((result: GeneralCallbackResult) => void)

失败的回调函数

firstIpv4?: boolean

DNS解析时优先使用 ipv4

forceCellularNetwork?: boolean

wifi下使用移动网络发送请求

getResponse?: boolean

返回原生响应 UniAppResponse 默认false

header?: any

设置请求的 header,header 中不能设置 Referer。

httpDNSServiceId?: boolean

HttpDNS 服务商 Id。 HttpDNS 用法详见 移动解析HttpDNS

ignoreLoading?: boolean

忽略 loading 提示

method?:
    | "GET"
    | "POST"
    | "PUT"
    | "DELETE"
    | "HEAD"
    | "OPTIONS"
    | "TRACE"
    | "CONNECT"

默认为 GET 可以是:OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT

params?: any

get 请求参数

responseType?: string

设置响应的数据类型。合法值:text、arraybuffer

sslVerify?: boolean

验证 ssl 证书

success?: ((result: RequestSuccessCallbackResult) => void)
timeout?: number

超时时间

url?: string

资源url

withCredentials?: boolean

跨域请求时是否携带凭证