| ¶Ô±ÈÐÂÎļþ |
| | |
| | | type AnyObject = Record<string | number | symbol, any> |
| | | type HttpPromise<T> = Promise<HttpResponse<T>>; |
| | | type Tasks = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask |
| | | export interface RequestTask { |
| | | abort: () => void; |
| | | offHeadersReceived: () => void; |
| | | onHeadersReceived: () => void; |
| | | } |
| | | export interface HttpRequestConfig<T = Tasks> { |
| | | /** 请æ±åºå°å */ |
| | | baseURL?: string; |
| | | /** è¯·æ±æå¡å¨æ¥å£å°å */ |
| | | url?: string; |
| | | |
| | | /** è¯·æ±æ¥è¯¢åæ°ï¼èªå¨æ¼æ¥ä¸ºæ¥è¯¢å符串 */ |
| | | params?: AnyObject; |
| | | /** 请æ±ä½åæ° */ |
| | | data?: AnyObject; |
| | | |
| | | /** æä»¶å¯¹åºç key */ |
| | | name?: string; |
| | | /** HTTP 请æ±ä¸å
¶ä»é¢å¤ç form data */ |
| | | formData?: AnyObject; |
| | | /** è¦ä¸ä¼ æä»¶èµæºçè·¯å¾ã */ |
| | | filePath?: string; |
| | | /** éè¦ä¸ä¼ çæä»¶å表ãä½¿ç¨ files æ¶ï¼filePath å name ä¸çæï¼AppãH5ï¼ 2.6.15+ï¼ */ |
| | | files?: Array<{ |
| | | name?: string; |
| | | file?: File; |
| | | uri: string; |
| | | }>; |
| | | /** è¦ä¸ä¼ çæä»¶å¯¹è±¡ï¼ä»
H5ï¼2.6.15+ï¼æ¯æ */ |
| | | file?: File; |
| | | |
| | | /** 请æ±å¤´ä¿¡æ¯ */ |
| | | header?: AnyObject; |
| | | /** è¯·æ±æ¹å¼ */ |
| | | method?: "GET" | "POST" | "PUT" | "DELETE" | "CONNECT" | "HEAD" | "OPTIONS" | "TRACE" | "UPLOAD" | "DOWNLOAD"; |
| | | /** å¦æè®¾ä¸º jsonï¼ä¼å°è¯å¯¹è¿åçæ°æ®å䏿¬¡ JSON.parse */ |
| | | dataType?: string; |
| | | /** 设置ååºçæ°æ®ç±»åï¼æ¯ä»å®å°ç¨åºä¸æ¯æ */ |
| | | responseType?: "text" | "arraybuffer"; |
| | | /** èªå®ä¹åæ° */ |
| | | custom?: AnyObject; |
| | | /** è¶
æ¶æ¶é´ï¼ä»
微信å°ç¨åºï¼2.10.0ï¼ãæ¯ä»å®å°ç¨åºæ¯æ */ |
| | | timeout?: number; |
| | | /** DNSè§£ææ¶ä¼å
使ç¨ipv4ï¼ä»
App-Android æ¯æ (HBuilderX 2.8.0+) */ |
| | | firstIpv4?: boolean; |
| | | /** éªè¯ ssl è¯ä¹¦ ä»
5+Appå®åç«¯æ¯æï¼HBuilderX 2.3.3+ï¼ */ |
| | | sslVerify?: boolean; |
| | | /** è·¨åè¯·æ±æ¶æ¯å¦æºå¸¦åè¯ï¼cookiesï¼ä»
H5æ¯æï¼HBuilderX 2.6.15+ï¼ */ |
| | | withCredentials?: boolean; |
| | | |
| | | /** è¿åå½å请æ±çtask, optionsã请å¿å¨æ¤å¤ä¿®æ¹optionsã */ |
| | | getTask?: (task: T, options: HttpRequestConfig<T>) => void; |
| | | /** å
¨å±èªå®ä¹éªè¯å¨ */ |
| | | validateStatus?: (statusCode: number) => boolean | void; |
| | | } |
| | | export interface HttpResponse<T = any> { |
| | | config: HttpRequestConfig; |
| | | statusCode: number; |
| | | cookies: Array<string>; |
| | | data: T; |
| | | errMsg: string; |
| | | header: AnyObject; |
| | | } |
| | | export interface HttpUploadResponse<T = any> { |
| | | config: HttpRequestConfig; |
| | | statusCode: number; |
| | | data: T; |
| | | errMsg: string; |
| | | } |
| | | export interface HttpDownloadResponse extends HttpResponse { |
| | | tempFilePath: string; |
| | | } |
| | | export interface HttpError { |
| | | config: HttpRequestConfig; |
| | | statusCode?: number; |
| | | cookies?: Array<string>; |
| | | data?: any; |
| | | errMsg: string; |
| | | header?: AnyObject; |
| | | } |
| | | export interface HttpInterceptorManager<V, E = V> { |
| | | use( |
| | | onFulfilled?: (config: V) => Promise<V> | V, |
| | | onRejected?: (config: E) => Promise<E> | E |
| | | ): void; |
| | | eject(id: number): void; |
| | | } |
| | | export abstract class HttpRequestAbstract { |
| | | constructor(config?: HttpRequestConfig); |
| | | config: HttpRequestConfig; |
| | | interceptors: { |
| | | request: HttpInterceptorManager<HttpRequestConfig, HttpRequestConfig>; |
| | | response: HttpInterceptorManager<HttpResponse, HttpError>; |
| | | } |
| | | middleware<T = any>(config: HttpRequestConfig): HttpPromise<T>; |
| | | request<T = any>(config: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | get<T = any>(url: string, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | upload<T = any>(url: string, config?: HttpRequestConfig<UniApp.UploadTask>): HttpPromise<T>; |
| | | delete<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | head<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | post<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | put<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | connect<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | options<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | trace<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; |
| | | |
| | | download(url: string, config?: HttpRequestConfig<UniApp.DownloadTask>): Promise<HttpDownloadResponse>; |
| | | |
| | | setConfig(onSend: (config: HttpRequestConfig) => HttpRequestConfig): void; |
| | | } |
| | | |
| | | declare class HttpRequest extends HttpRequestAbstract { } |
| | | export default HttpRequest; |