如何从颤振中的流式响应中获取响应? [复制]

2024-02-28

我正在使用 flutter 开发一个应用程序,并使用 http 库来调用我构建的 api。

我想发出一个多部分请求来发送文件,它也发送它,但我无法从服务器收到任何响应,因为返回的对象是 StreamResponse。

请告诉我如何获取回复的正文。

代码片段:

var request = http.MultipartRequest('POST', Uri.parse('$SERVER_URL/signup'));
    request.files.add(await http.MultipartFile.fromPath(
      'image',
      user.image,
      filename: 'image',
      contentType: MediaType('multipart/form-data', 'multipart/form-data'),
    ));



    StreamResponse x = await request.send();
    //get body of the response


Thanks,


只需使用 http.Response.fromStream()

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

var streamedResponse = await request.send();
var response = await http.Response.fromStream(streamedResponse);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从颤振中的流式响应中获取响应? [复制] 的相关文章

随机推荐