Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
780 views
in Technique[技术] by (71.8m points)

flutter - dio post send progress 100% then connection closed exception

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...