I'm sending fields of texts & images with dio POST,
Future<Response> postForm(
String url, Map<String, String> fields, Map<String, File> images) async {
try {
fieldsMapEntryList = readFields(fields);
filesMapEntryList = await readImagesFiles(images);
var formData = await getFormData(fieldsMapEntryList, filesMapEntryList);
Response response;
var dio = DioUtils.createDio();
dio.interceptors.add(LogInterceptor());
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {
client.findProxy = (uri) {
return "PROXY x.x.x.x:5432";
};
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
};
response = await dio.post(
"http://x.x.x.x:5432/myapp/myappdata/shop",
data: formData,
onSendProgress: (received, total) {
if (total != -1) {
print((received / total * 100).toStringAsFixed(0) + "%");
}
},
);
} catch (err) {
err.toString();
}
return response;
}
I get onSendProgress result 100% ..then immediately Dio Error HttpException connection closed before full heade ...
myapp is a postgresql DB name , myappdata is the schema , shop is the table.
I'm using physical device.
My Options :
static BaseOptions baseOptions = BaseOptions(
method: 'POST',
connectTimeout: 30000,
sendTimeout: 30000,
receiveTimeout: 60000,
baseUrl: "http://x.x.x.x:5432/myapp/myappdata/shop",
headers: {
HttpHeaders.cacheControlHeader: 'max-age=3600, must-revalidate',
HttpHeaders.authorizationHeader : 'Basic api token',
HttpHeaders.contentTypeHeader : 'multipart/form-data',
},
responseType: ResponseType.json,
contentType: "multipart/form-data",
validateStatus: (int) {
int = 200;
return true;
},
receiveDataWhenStatusError: false,
followRedirects: false,
maxRedirects: 0,
requestEncoder: (stringValue, requestOptions) {
List<int> requestEncoderList;
return requestEncoderList;
},
responseDecoder: (intListValue, requestOptions, responseBody) {
String responseDecoderString;
return responseDecoderString;
},
);
Most answers on Git and here suggest downgrade to API 28 (Pie)..I did with no effect.
Many days with no avail ... any ideas would be appreciated !! Thanks
question from:
https://stackoverflow.com/questions/65933534/dio-post-send-progress-100-then-connection-closed-exception 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…