본문 바로가기
Flutter/Flutter FAQ

Flutter request.send()를 사용하여 응답 본문을 어떻게 가져올 수 있나요?, How to get response body with request.send() in dart

by 베타코드 2023. 8. 16.
반응형

질문


I'm doing an api request uploading an image with

var request = new http.MultipartRequest("POST", uri);
var response = await request.send()

in dart using flutter. I can then check the response code with for instance

if (response.statusCode == 200) {
   print('ok');
}

with other calls I can also get the response body with

var result = response.body;

however when using request.send() I can't seem to find out how to get the response body result.

Any help or input is very much appreciated, thanks!


답변


그냥 http.Response.fromStream()을 사용하세요.

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

var streamedResponse = await request.send()
var response = await http.Response.fromStream(streamedResponse);
반응형

댓글