statistics.dart 907 B

123456789101112131415161718192021222324252627282930
  1. import 'dart:convert';
  2. import 'package:http/http.dart' as http;
  3. import 'package:logging/logging.dart';
  4. final Logger _log = Logger('statistics.dart');
  5. class Statistics {
  6. static String get eventUri => 'https://pcoloring.com/napi/event/v2';
  7. static postEvent(Map data) async {
  8. try {
  9. _log.info(jsonEncode(data));
  10. final response = await http.post(
  11. Uri.parse(eventUri),
  12. headers: <String, String>{
  13. 'Content-Type': 'application/json; charset=UTF-8',
  14. },
  15. body: jsonEncode(data),
  16. );
  17. if (response.statusCode != 200) {
  18. // throw Exception('Invalid status code: ${response.statusCode} when post event to: $eventUri');
  19. _log.info('Invalid status code: ${response.statusCode} when post event to: $eventUri');
  20. }
  21. _log.info('${response.statusCode}, $eventUri');
  22. } catch (error) {
  23. _log.info('$error');
  24. }
  25. }
  26. }