call function

Future call(
  1. Uri url,
  2. String methodName,
  3. List params, {
  4. Map<String, String>? headers,
  5. Encoding encoding = utf8,
  6. HttpPost? httpPost,
  7. List<Codec>? encodeCodecs,
  8. List<Codec>? decodeCodecs,
})

Make a xmlrpc call to the given url, which can be a Uri or a String.

Implementation

Future call(
  Uri url,
  String methodName,
  List params, {
  Map<String, String>? headers,
  Encoding encoding = utf8,
  HttpPost? httpPost,
  List<Codec>? encodeCodecs,
  List<Codec>? decodeCodecs,
}) async {
  encodeCodecs ??= standardCodecs;
  decodeCodecs ??= standardCodecs;

  final xml = convertMethodCall(methodName, params, encodeCodecs).toXmlString();

  final _headers = <String, String>{
    'Content-Type': 'text/xml',
    if (headers != null) ...headers,
  };

  final post = httpPost ?? http.post;
  final response =
      await post(url, headers: _headers, body: xml, encoding: encoding);
  if (response.statusCode != 200) throw response;
  final body = response.body;
  final value = decodeResponse(XmlDocument.parse(body), decodeCodecs);
  if (value is Fault) {
    throw value;
  } else {
    return value;
  }
}