颤振中的肥皂请求

Soap request in flutter

我正在尝试向 http://www.dneonline.com/calculator.asmx 发送 soap 请求以添加 2 个号码

ElevatedButton(
                onPressed: () async {
                  var request="""
                    <?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>
                        <Add xmlns="http://tempuri.org/">
                          <intA>1</intA>
                          <intB>2</intB>
                        </Add>
                      </soap:Body>
                    </soap:Envelope>
                  """;
                  http.Response response =
                      await http.post(
                        Uri.parse('http://www.dneonline.com/calculator.asmx'),
                        headers: {
                          "Content-Type": "text/xml; charset=utf-8",
                          "Host": "www.dneonline.com",
                          "Content-Length": request.length.toString(),
                          "SOAPAction": "http://tempuri.org/Add"
                        },
                        body: request
                      );
                  print(response.body);
                },
                child: new Text("Calculate"),
              )

但是我收到一个错误

错误:XMLHttpRequest 错误。

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 910:28                get current

packages/http/src/browser_client.飞镖69:22

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1685:54 runUnary

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 159:18 handleValue

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 766:44 handleValueCallback

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 795:13 _propagateToListeners C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 592:7 [_complete]

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream.dart 1288:7

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall

C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37301:58

at Object.createErrorWithStack (http://localhost:65501/dart_sdk.js:5080:12)

at Function._throw (http://localhost:65501/dart_sdk.js:20337:18)

at Function.throwWithStackTrace (http://localhost:65501/dart_sdk.js:20334:18)

at async._AsyncCallbackEntry.new.callback (http://localhost:65501/dart_sdk.js:40851:18)

at Object._microtaskLoop (http://localhost:65501/dart_sdk.js:40708:13)

at _startMicrotaskLoop (http://localhost:65501/dart_sdk.js:40714:13)

at http://localhost:65501/dart_sdk.js:36191:9

我正在使用 android studio

http:^0.13.4

xml:^5.3.1

请大家帮忙

编辑:

更新

我在网络上尝试时遇到了 cors 问题。 现在我在 android 中尝试,我得到一个 400 StatusCode

Statuscode and body image

SoapUI 输出

soapui

在这里你可以检查这个。它对我有用

import 'package:http/http.dart';
import 'dart:convert';



  _hitApi() async {
    
       var requestBody ='''<?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>
        <Add xmlns="http://tempuri.org/">
          <intA>2</intA>
          <intB>4</intB>
        </Add>
      </soap:Body>
    </soap:Envelope>''';
    
    
       Response response = await post(
         Uri.parse('http://www.dneonline.com/calculator.asmx'),
         headers: {
           'content-type': 'text/xml; charset=utf-8',
           'SOAPAction': 'http://tempuri.org/Add',
            'Host': 'www.dneonline.com',
         },
         body: utf8.encode(requestBody),
        
       );
    
    
       print("Response status: ${response.statusCode}");
       print("Response body: ${response.body}");
     }

这是回应:

 <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><AddResponse
    xmlns="http://tempuri.org/"><AddResult>6</AddResult></AddResponse></soap:Body></soap:Envelope>