From 92a0291fcc86905575f897023de31fa974c3535b Mon Sep 17 00:00:00 2001 From: Aiden2014 Date: Mon, 11 Nov 2024 17:23:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80?= =?UTF-8?q?=E4=B8=93=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/html.dart | 2 +- lib/http/init.dart | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/http/html.dart b/lib/http/html.dart index 100887e5..26c3bb23 100644 --- a/lib/http/html.dart +++ b/lib/http/html.dart @@ -70,7 +70,7 @@ class HtmlHttp { static Future reqReadHtml(id, dynamicType) async { var response = await Request().get( "https://www.bilibili.com/$dynamicType/$id/", - extra: {'ua': 'pc'}, + extra: {'ua': 'pc', 'opus-goback': '1'}, ); Document rootTree = parse(response.data); Element body = rootTree.body!; diff --git a/lib/http/init.dart b/lib/http/init.dart index a0b36369..6e292e16 100644 --- a/lib/http/init.dart +++ b/lib/http/init.dart @@ -95,9 +95,9 @@ class Request { String spmPrefix = spmPrefixExp.firstMatch(html.data)!.group(1)!; Random rand = Random(); String rand_png_end = base64.encode( - List.generate(32, (_) => rand.nextInt(256)) + - List.filled(4, 0) + - [73, 69, 78, 68] + + List.generate(32, (_) => rand.nextInt(256)) + + List.filled(4, 0) + + [73, 69, 78, 68] + List.generate(4, (_) => rand.nextInt(256)) ); @@ -112,7 +112,7 @@ class Request { await Request().post( Api.activateBuvidApi, - data: {'payload': jsonData}, + data: {'payload': jsonData}, options: Options(contentType: 'application/json') ); } @@ -197,6 +197,15 @@ class Request { if (extra['ua'] != null) { options.headers = {'user-agent': headerUa(type: extra['ua'])}; } + if (extra['opus-goback'] != null) { + List cookies = await cookieManager.cookieJar + .loadForRequest(Uri.parse(HttpString.baseUrl)); + String cookieHeader = cookies + .map((cookie) => '${cookie.name}=${cookie.value}') + .join('; '); + options.headers!['cookie'] = + '$cookieHeader; opus-goback = ${extra['opus-goback']}'; + } } options.responseType = resType;