fix: failed to view article

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-11 19:00:16 +08:00
parent 391400a94d
commit 2d391a5a6c
3 changed files with 10 additions and 6 deletions

View File

@@ -17,7 +17,7 @@ class DanmakaHttp {
var response = await Request().get(
Api.webDanmaku,
data: params,
extra: {'resType': ResponseType.bytes},
options: Options(responseType: ResponseType.bytes),
);
if (response.statusCode != 200 || response.data == null) {
return DmSegMobileReply();

View File

@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:PiliPalaX/models/dynamics/article_content_model.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:html/dom.dart' as dom;
import 'package:html/parser.dart' as parser;
@@ -76,6 +77,11 @@ class HtmlHttp {
var response = await Request().get(
"https://www.bilibili.com/$dynamicType/$id/",
extra: {'ua': 'pc'},
options: Options(
headers: {
'cookie': 'opus-goback=1',
},
),
);
if (response.data is! String && response.data is! List<int>) {
return;

View File

@@ -191,15 +191,13 @@ class Request {
*/
Future get(url, {data, options, cancelToken, extra}) async {
Response response;
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.headers ??= <String, dynamic>{};
options.headers!['user-agent'] = headerUa(type: extra['ua']);
}
}
options.responseType = resType;
try {
response = await dio.get(