How to get response body with request.send() in dart

前端 未结 4 466
说谎
说谎 2021-02-04 02:30

I\'m doing an api request uploading an image with

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

i

4条回答
  •  执笔经年
    2021-02-04 03:00

    I checked the docs for request.send I returns Future instead of Future

    Digging more for StreamedResponse I found that it response.stream which is a ByteStream

    Here is what you can do to get response in String

    final response = await request.send();
    final respStr = await response.stream.bytesToString();
    

    In my opinoin you should only use request.send if you want streamed response instead of "collected" response. More about streams in dart here

提交回复
热议问题