send static method

Future<String> send(
  1. String url,
  2. String requestData
)

Send the SOAP requestData to the given url endpoint.

Implementation

static Future<String> send(String url, String requestData) async {
  Response? response = null;

  try {
    response = await dio.post(url,
        data: requestData,
        options: Options(headers: {
          Headers.contentTypeHeader: 'text/xml; charset=utf-8',
          Headers.contentLengthHeader: requestData.length
        }));
  } on DioError catch (error) {
    if (error.response?.statusCode == 500) {
      final jsonMap = OnvifUtil.xmlToMap(error.response?.data);

      final envelope = Envelope.fromJson(jsonMap);

      if (envelope.body.hasFault) {
        throw Exception("Error code: ${envelope.body.fault}");
      }
    }

    throw Exception(error.toString());
  }

  return response.data;
}