call function
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 post = httpPost ?? http.post;
final response = await post(
url,
headers: {
'Content-Type': 'text/xml',
...?headers,
},
body: xml,
encoding: encoding,
);
if (response.statusCode != 200) throw response;
final body = response.body;
final value = decodeResponse(XmlDocument.parse(body), decodeCodecs);
return switch (value) {
Fault() => throw value,
_ => value,
};
}