首页 > 解决方案 > 未来的颤振问题

问题描述

返回类型“响应”有问题。我真的不知道如何处理这种类型。我必须转换它。我只想显示对屏幕的响应。

有人可以解释这个问题吗?

  var username = 'dslf-config';
  var password = '53259721';
  static String port = "37443";
  String url = 'https://192.168.2.1:' + port;
  //unused.... String parameter = 'Device.DeviceInfo.ModelName';

  var body = """
    <?xml version="1.0" encoding= "UTF-8" ?>
    <soap-env:Envelope soap-enc="http://schemas.xmlsaop.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cwmp="urn:telekom-de.totr64-2-n">
        <soap-env:Body>
            <cwmp:GetParameterValues xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
                <cwmp:ParameterNames soap-env:arrayType="xsd:string[10]">
                    <xsd:string>Device.DeviceInfo.ModelName</xsd:string>
                </cwmp:ParameterNames>
            </cwmp:GetParameterValues>
        </soap-env:Body>
    </soap-env:Envelope>""";

  Future<http.Response> getData2() {
    bool trustSelfSigned = true;
    Map<String, String> headers = {
      "Accept": "*/*",
      "Content-Type": "text/xml",
      "SOAPAction":
          "urn:telekom-de:device:TO_InternetGatewayDevice:2#GetParameterValues"
    };

    HttpClient httpClient = new HttpClient()
      ..badCertificateCallback =
          ((X509Certificate cert, String host, int port) => trustSelfSigned);

    httpClient.addCredentials(Uri.parse(url), "theRealm",
        new HttpClientDigestCredentials(username, password));

    IOClient ioClient = new IOClient(httpClient);

    return ioClient.post(Uri.parse(url), headers: headers, body: body); 
  }

  getData3() async {
    final response = await getData2();
    print(response.body);
    print(response.statusCode);
    print(response.headers);
  }

标签: httpflutterxmlhttprequestresponsehttpresponse

解决方案


目前还不清楚你的问题是什么。如果您希望您的响应正文显示在您的应用程序中,您可以简单地将其放在一个Text小部件中,例如Text(response.body).

如果是关于 HTTP 响应,那么我建议您阅读一篇关于 HTTP 请求和响应如何工作的文章。Flutter 中的http.Response类只是解析原始 HTTP 响应并将其呈现给用户。


推荐阅读