【问题标题】:Flutter: how to get the http response headerFlutter:如何获取http响应头
【发布时间】:2021-09-08 08:32:24
【问题描述】:

我尝试向服务器发布数据的方式,然后服务器为我返回封装在响应头中的详细消息,如何从响应头中获取此消息?

var response = await http.post(...);
var detail_message = response['header'];

【问题讨论】:

    标签: flutter


    【解决方案1】:

    如果标题响应,您必须解码您的响应数据

    var decodedData = jsonDecode(response);
    var detail_message = decodedData['header'];
    

    否则:

    var detail_message = response.headers;
    

    【讨论】:

      【解决方案2】:

      https://pub.dev/documentation/http/latest/http/Response-class.html

      var response = await http.post(...);
      print('Response status: ${response.statusCode}');
      print('Response body: ${response.headers}');
      print('Response body: ${response.body}');
      

      【讨论】:

        猜你喜欢
        • 2016-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-06
        • 1970-01-01
        • 2020-03-25
        • 1970-01-01
        相关资源
        最近更新 更多