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 _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;
}
}