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

前端 未结 4 469
说谎
说谎 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 02:53

    Your MultipartRequest returns a Streamed Response since you used request.send. You will need to extract the string value from the response like below:

    import 'package:http/http.dart'
    
    var request = new MultipartRequest("POST", uri);
    var response = await request.send()
    
    // Extract String from Streamed Response
    var responseString = await response.stream.bytesToString();
    

    In this case the responseString will be just like response.body of

    final response = await post(URL, body : map);
    

提交回复
热议问题