send method

Future<Response> send(
  1. XmlDocumentFragment xmlDoc
)

send to the printer server xmlDoc returns

Implementation

Future<Response> send(XmlDocumentFragment xmlDoc) async {
  /// build the printer server url based on config
  final config = getConfig();

  var url = 'http://${config.host}/cgi-bin/fpmate.cgi';
  // var url = '${config.host}';
  var prefix = '?';
  if (config.deviceId != null) {
    url += '${prefix}devid=${config.deviceId}';
    prefix = '&';
  }
  if (config.timeout != null && config.timeout > 0) {
    url += '${prefix}timeout=${config.timeout}';
  }

  /// build xml string
  final xmlStr = parseRequest(xmlDoc);

  /// send
  final headers = {
    'Content-Type': 'text/xml;charset=utf-8',
  };
  final options = BaseOptions(headers: headers);


  // 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("epson_send_request=================");
  print(headers);
  print(url);
  print(xmlStr);
  //============

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



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