From 427bd2eb79ca4298b900f46a34a1f498ff0f4793 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 17 Sep 2023 23:37:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/init.dart | 27 +++++++++++++++------------ lib/pages/about/index.dart | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/http/init.dart b/lib/http/init.dart index f927e2e5..1e33365d 100644 --- a/lib/http/init.dart +++ b/lib/http/init.dart @@ -89,11 +89,7 @@ class Request { //响应流上前后两次接受到数据的间隔,单位为毫秒。 receiveTimeout: const Duration(milliseconds: 12000), //Http请求头. - headers: { - 'keep-alive': 'true', - 'user-agent': headerUa(), - }, - persistentConnection: true, + headers: {}, ); dio = Dio(options) @@ -128,12 +124,14 @@ class Request { */ get(url, {data, options, cancelToken, extra}) async { Response response; - Options options; + Options options = Options(); ResponseType resType = ResponseType.json; if (extra != null) { resType = extra!['resType'] ?? ResponseType.json; + if (extra['ua'] != null) { + options.headers = {'user-agent': headerUa(type: extra['ua'])}; + } } - options = Options(); options.responseType = resType; try { response = await dio.get( @@ -201,14 +199,19 @@ class Request { token.cancel("cancelled"); } - String headerUa() { + String headerUa({type = 'mob'}) { String headerUa = ''; - if (Platform.isIOS) { - headerUa = - 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 Safari/604.1'; + if (type == 'mob') { + if (Platform.isIOS) { + headerUa = + 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Mobile/15E148 Safari/604.1'; + } else { + headerUa = + 'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36'; + } } else { headerUa = - 'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Mobile Safari/537.36'; + 'Mozilla/5.0 (MaciMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'; } return headerUa; } diff --git a/lib/pages/about/index.dart b/lib/pages/about/index.dart index 76173fae..31808e1c 100644 --- a/lib/pages/about/index.dart +++ b/lib/pages/about/index.dart @@ -184,7 +184,7 @@ class AboutController extends GetxController { // 获取远程版本 Future getRemoteApp() async { - var result = await Request().get(Api.latestApp); + var result = await Request().get(Api.latestApp, extra: {'ua': 'pc'}); data = LatestDataModel.fromJson(result.data); remoteAppInfo = data; remoteVersion.value = data.tagName!;