Flutter肥皂:Flutter中SOAP请求的正确格式是什么

lymgl2op  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(135)

我需要使用Flutter向.NET Web服务(aspx)发出SOAP请求。下面是我的代码:

sendSoapRequest() async {
    final url =
        Uri.parse('url');
    const soapAction = '';

    const xmlBody = '''
    <?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>
        <LoginPage_LoginBtnClk xmlns="http://tempuri.org/">
          <txtUserName1>JECLERK</txtUserName1>
          <txtpasswd1>PASS@1234</txtpasswd1>
        </LoginPage_LoginBtnClk>
      </soap:Body>
    </soap:Envelope>
  ''';
    final response = await http
        .post(url,
            headers: {
              'Content-Type': 'text/xml; charset=utf-8',
              'Host': 'tdrapp.justservices.in',
              'SOAPAction': soapAction,
            },
            body: utf8.encode(xmlBody),
            encoding: Encoding.getByName("UTF-8"))
        .then((onValue) {
      print(onValue);
      print("Response status: ${onValue.statusCode}");
      print("Response status: ${onValue.body}");
    });
    print(response);
     if (response.statusCode == 200) {
        final parsedResponse = xml.XmlDocument.parse(response.body);
        // Process the SOAP XML response as needed
        print(parsedResponse);
        return response.body;
      } else {
        throw Exception('Failed to send SOAP request: ${response.statusCode}');
      }
    // return response.body;
  }

但状态码是400少了什么?

unhi4e5o

unhi4e5o1#

我建议您使用一个工具https://easywsdl.com/,它将生成连接到SOAP Web服务所需的所有代码。在这种情况下,您将保存大量时间来创建正确的代码来解析SOAP消息,并且您也不会在应用程序中引入错误-从头开始创建这样的代码可能是一项艰巨的任务。

相关问题