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;