56 lines
1.4 KiB
Dart
56 lines
1.4 KiB
Dart
/*
|
|
* 文件: test_ingredient_cache.dart
|
|
* 名称: 食材缓存测试脚本
|
|
* 作用: 验证食材缓存服务的读写功能
|
|
* 创建: 2026-04-14
|
|
*/
|
|
|
|
import 'dart:io';
|
|
|
|
void main() async {
|
|
print('========================================');
|
|
print('食材缓存测试脚本');
|
|
print('========================================\n');
|
|
|
|
// 测试 API 接口
|
|
await testIngredientApi();
|
|
|
|
print('\n========================================');
|
|
print('测试完成');
|
|
print('========================================');
|
|
}
|
|
|
|
Future<void> testIngredientApi() async {
|
|
final testIds = [849, 1248, 1, 1206, 1209];
|
|
|
|
for (final id in testIds) {
|
|
print('\n--- 测试食材 ID: $id ---');
|
|
|
|
try {
|
|
final client = HttpClient();
|
|
final request = await client.getUrl(
|
|
Uri.parse('https://eat.wktyl.com/api/api.php?act=ingredient_detail&id=$id'),
|
|
);
|
|
|
|
final response = await request.close();
|
|
final body = await response.transform(const SystemEncoding().decoder).join();
|
|
|
|
print('状态码: ${response.statusCode}');
|
|
print('响应长度: ${body.length} 字符');
|
|
|
|
if (body.isNotEmpty && body.startsWith('{')) {
|
|
print('✅ API 响应正常');
|
|
} else {
|
|
print('❌ API 响应异常');
|
|
}
|
|
|
|
client.close();
|
|
} catch (e) {
|
|
print('❌ 请求失败: $e');
|
|
}
|
|
|
|
// 延迟避免请求过快
|
|
await Future.delayed(const Duration(milliseconds: 500));
|
|
}
|
|
}
|