http
http copied to clipboard
How I can get response data when calling multipart post request ?
Sample code is here
final request = http.MultipartRequest('POST', Uri.parse("your_server_url"));
request.files.add(http.MultipartFile.fromBytes("file", file.bytes, filename: file.name)); //your server may require a different key than "file"
final response = await request.send();
// Now I want to get response data, How can I get it ?
if (response.statusCode == 200) {
print("Response : ${response.body}"); // here I want to print the response.
}
@aniketsongara you can use like this:
final respStr = await response.stream.bytesToString();
then respStr
will contain the "response"
@aniketsongara or you can use this: http.Response response = await http.Response.fromStream(await request.send()); ( json.decode(response.body) as Map<String, dynamic>)
var response = await request.send(); var responseData = await response.stream.bytesToString(); final decodedMap = json.decode(responseData);
The decodedMap contains response the "json format of response"