opt: request get options
This commit is contained in:
@ -17,7 +17,9 @@ class DanmakaHttp {
|
|||||||
var response = await Request().get(
|
var response = await Request().get(
|
||||||
Api.webDanmaku,
|
Api.webDanmaku,
|
||||||
data: params,
|
data: params,
|
||||||
extra: {'resType': ResponseType.bytes},
|
options: Options(
|
||||||
|
responseType: ResponseType.bytes,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return DmSegMobileReply.fromBuffer(response.data);
|
return DmSegMobileReply.fromBuffer(response.data);
|
||||||
}
|
}
|
||||||
|
@ -209,24 +209,12 @@ class Request {
|
|||||||
*/
|
*/
|
||||||
get(url, {data, Options? options, cancelToken, extra}) async {
|
get(url, {data, Options? options, cancelToken, extra}) async {
|
||||||
Response response;
|
Response response;
|
||||||
options ??= Options(); // 如果 options 为 null,则初始化一个新的 Options 对象
|
|
||||||
ResponseType resType = ResponseType.json;
|
|
||||||
|
|
||||||
if (extra != null) {
|
if (extra != null) {
|
||||||
resType = extra['resType'] ?? ResponseType.json;
|
|
||||||
if (extra['ua'] != null) {
|
if (extra['ua'] != null) {
|
||||||
options.headers = {'user-agent': headerUa(type: extra['ua'])};
|
options ??= Options();
|
||||||
}
|
options.headers!['user-agent'] = headerUa(type: extra['ua']);
|
||||||
if (extra['opus-goback'] != null) {
|
|
||||||
if (extra['opus-goback'] != null) {
|
|
||||||
String cookieHeader = dio.options.headers['cookie'];
|
|
||||||
options.headers!['cookie'] =
|
|
||||||
'$cookieHeader; opus-goback = ${extra['opus-goback']}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.responseType = resType;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await dio.get(
|
response = await dio.get(
|
||||||
url,
|
url,
|
||||||
|
@ -65,7 +65,12 @@ class ReadHttp {
|
|||||||
static Future parseArticleCv({required String id}) async {
|
static Future parseArticleCv({required String id}) async {
|
||||||
var res = await Request().get(
|
var res = await Request().get(
|
||||||
'https://www.bilibili.com/read/cv$id',
|
'https://www.bilibili.com/read/cv$id',
|
||||||
extra: {'ua': 'pc', 'opus-goback': '1'},
|
extra: {'ua': 'pc'},
|
||||||
|
options: Options(
|
||||||
|
headers: {
|
||||||
|
'cookie': 'opus-goback=1',
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
String scriptContent =
|
String scriptContent =
|
||||||
extractScriptContents(parse(res.data).body!.outerHtml)[0];
|
extractScriptContents(parse(res.data).body!.outerHtml)[0];
|
||||||
|
Reference in New Issue
Block a user