在Flutter中的SOAP请求中传递字符串列表

我正在发出SOAP请求,这是发送请求的方式:

  <id></id>
  <fieldList>
    <string>string</string>
    <string>string</string>
  </fieldList>

这是我制作信封的方式:

final int id = 21;
List<String> fieldList = new List<String>();

  fieldList = [
    "pinNumber:PIN0000074","dispatchArrivedTime:13.05","towedStatus:C"
  ];

var envelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    "<soap:Envelope "
    "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
    "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
    "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
    "<soap:Body>"
    "<update xmlns=\"http://example.com/\">"
    "<id>${id}</id>"
    "<fieldList>${fieldList}</fieldList>"
    "</update>"
    "</soap:Body>"
    "</soap:Envelope>";

    final response = await http.post(
    'http://example.com/vc/ws/towedvehicletable.asmx',headers: {
      "Content-Type": "text/xml; charset=utf-8","SOAPaction": "http://example.com/update","Host": "example.com"
      //"accept": "text/xml"
    },body: envelope);

但是,这种方法不起作用。如果有人可以告诉我如何将字符串列表传递到我的请求中,这将非常有帮助。我正在使用Flutter和Dart。谢谢

lj0122 回答:在Flutter中的SOAP请求中传递字符串列表

只需映射字符串列表,然后将其加入:

  List<String> fieldList = ['test1','test2'];
  final xmlValues = fieldList.map((v) => '<string>$v</string>').join();
  print(xmlValues);

打印:

<string>test1</string><string>test2</string>

还有一个package用于处理XML。它允许您解析和构造XML文档。

本文链接:https://www.f2er.com/3130026.html

大家都在问