send method

Future<Response> send(
  1. XmlDocument xmlDoc, [
  2. bool isGetInfo = false
])

send to the printer server xmlDoc returns

Implementation

Future<Response> send(XmlDocument xmlDoc, [bool isGetInfo = false]) async {
  // build the printer server url based on config
  final config = getConfig();
  final url = 'http://${config.host}/xml/printer.htm';
  // build xml string
  final xmlStr = _parseRequest(xmlDoc);
  // send
  final authorization =
      'Basic ${base64.encode(utf8.encode('${config.fiscalId ?? ''}:${config.fiscalId ?? ''}'))}';
  final headers = {
    'Content-Type': 'text/xml;charset=utf-8',
    'authorization': authorization,
  };

  // if (1 == 1) {
  //   (dio?.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
  //       (client) {
  //     client.findProxy = (uri) {
  //       return "PROXY 192.168.0.108:8888";//${Platform.environment['CHARLES_PROXY_IP']} //--dart-define=CHARLES_PROXY_IP=192.168.1.108
  //     };
  //     client.badCertificateCallback =
  //         (X509Certificate cert, String host, int port) => true;
  //   };
  // }
  //============
  print("custom_send_request=================");
  print(headers);
  print(url);
  print(xmlStr);
  //============

  final res = await Dio(BaseOptions(headers: headers)).post(url, data: xmlStr);

  final data = res.data;
  final resXmlStr = data;
  final response = parseResponse(data, isGetInfo);
  final req = res.requestOptions;
  response.request = {
    'path': req.path,
    'data': req.data,
    'headers': req.headers,
  };
  response.original = Original(
    req: xmlStr,
    res: resXmlStr,
  );
  return response;
}