【问题标题】:flutter problems w/ Future<http.Response>颤振问题 w/ Future<http.Response>
【发布时间】:2019-11-13 12:39:09
【问题描述】:

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

谁能解释一下这个问题?

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

【问题讨论】:

    标签: http flutter xmlhttprequest response httpresponse


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 2021-05-05
      • 2022-01-12
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2022-06-29
      • 2020-09-26
      相关资源
      最近更新 更多