HttpClient class

Dio HTTP 封装。

  • BaseURL 来自 init(即 initSDK 的 apiAddr)
  • 通过拦截器自动注入 Authorization: Bearer <token>Accept-Language(默认 zh-CN
  • HTTP 整包 AES(aesKey 与后端 app.aes_key 一致)
  • go-chat 成功响应当作 protobuf JSON 直接返回(无 code/data 包装)
  • 失败响应形如 { "code": 401, "message": "..." }

Constructors

HttpClient()

Properties

acceptLanguage String
no setter
baseUrl String
no setter
hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
no setter
onTokenRefreshed ↔ void Function(String newToken)?
Token 刷新回调(服务端 Refresh-Access-Token 头)
getter/setter pair
onUnauthorized ↔ void Function()?
Token 失效回调
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token String?
no setter

Methods

clearToken() → void
dispose() → void
get(String path, {Map<String, dynamic>? query, CancelToken? cancelToken}) Future<Map<String, dynamic>>
GET 请求(如文件下载链接)
init({required String baseUrl, required String aesKey, Duration? connectTimeout, String? acceptLanguage}) → void
初始化 Dio,baseUrl 例如 http://127.0.0.1:9501 acceptLanguage 默认 zh-CN,有值则以客户端传入为准。
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
post(String path, {Map<String, dynamic>? data, CancelToken? cancelToken, Duration? sendTimeout, Duration? receiveTimeout}) Future<Map<String, dynamic>>
POST JSON,成功时返回响应体 Map;失败抛 GoChatException
postFormData(String path, {required FormData data, CancelToken? cancelToken, void onSendProgress(int sent, int total)?, Duration? sendTimeout, Duration? receiveTimeout}) Future<Map<String, dynamic>>
POST multipart/form-data(明文,跳过 AES),用于文件上传。
setAcceptLanguage(String value) → void
setToken(String? token) → void
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

asStringSafe(dynamic v, String def) String
formatAcceptLanguage(Locale locale) String
Flutter locale → languageCode-countryCode(countryCode 为空则仅 languageCode)。

Constants

defaultAcceptLanguage → const String