getXML method

Future<String> getXML(
  1. String url, {
  2. Map<String, String>? body,
  3. Map<String, String>? headers,
})

Implementation

Future<String> getXML(String url,
    {Map<String, String>? body, Map<String, String>? headers}) async {
  String? value='';
  if (kIsWeb) {
    var headers = {
      'content-type': 'application/x-www-form-urlencoded',
      //'Access-Control-Allow-Origin': '*',
      //'Access-Control-Allow-Credentials': 'true',
      //'Access-Control-Allow-Headers':
      //'Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
      //'Access-Control-Allow-Methods': 'POST, OPTIONS'
    };
    http.Response response;
    if (body != null)
      response = await http
          .post(Uri(path: url), headers: headers, body: body)
          .catchError((error, stackTrace) {
        _msg = error.message.toString();
        throw error;
      });
    else
      response = await http
          .post(Uri(path: url), headers: headers)
          .catchError((error) {
        _msg = error.message.toString();
        throw error;
      });
    value = response.body;
  } else {
    http.Request request = new http.Request('POST', Uri.parse(url));
    if (body != null) request.bodyFields = body;

    //await client.send(request);
    var client = new http.Client();

    await client
        .send(request)
        .then((response) => response.stream.bytesToString().then((txt) {
              value = txt;
            }))
        .catchError((error) {
      _msg = error.message.toString();
      throw error;
    });
  }
  return value!;
}