Tag Archives: DioError

Router DIO network request: dioerror[ DioErrorType.RESPONSE ]: HTTP status error [400] or [500]

DioError [DioErrorType.RESPONSE]: Http status error [400]

1) check if the request parameter is correct:

, for example, if the parameter value in the map is an array, the following code in the innerParticipateGroups and innerParticipators the value of the value can’t into the toString, otherwise it will be submitted to the 400

Map<String,dynamic> params = {
      "chamberId":resultId,
      "description":remark,
      "finishAt":1564979400000,
      "innerParticipateGroups":[],
      "innerParticipators":[],
      "name":meetingName,
      "reportId":"",
      "scheduleId":"",
      "startAt":1564975800000
    };

2) if above is correct, check the receive mode of parameters when get and post are called

see Dio(v2.1.0) GET request source code:

Future<Response<T>> get<T>(
    String path, {
    Map<String, dynamic> queryParameters,
    Options options,
    CancelToken cancelToken,
    ProgressCallback onReceiveProgress,
  }) {
    return request<T>(
      path,
      queryParameters: queryParameters,
      options: _checkOptions("GET", options),
      onReceiveProgress: onReceiveProgress,
      cancelToken: cancelToken,
    );
  }

queryParameters queryParameters

response = await dio.get(url, queryParameters: params);

POST source:

/// Handy method to make http POST request, which is a alias of  [Dio.request].
  Future<Response<T>> post<T>(
    String path, {
    data,
    Map<String, dynamic> queryParameters,
    Options options,
    CancelToken cancelToken,
    ProgressCallback onSendProgress,
    ProgressCallback onReceiveProgress,
  }) {
    return request<T>(
      path,
      data: data,
      options: _checkOptions("POST", options),
      queryParameters: queryParameters,
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );
  }

POST parameters data queryParameters; queryParameters; 400; queryParameters;

response = await dio.post(url, data : params);

DioError [dioerrortype.response]: Http status error [500]

Check if the header is set or set incorrectly

HttpGo() {
    dio = Dio(BaseOptions(
      baseUrl: 'https://www.***.com/',
      headers: getHeaders(),
      connectTimeout: 5000,
      receiveTimeout: 3000,
    ));
  }
  getHeaders () {
    return {
      'Accept':'application/json, text/plain, */*',
      'Content-Type':'application/json',
      'Authorization':"**",
      'User-Aagent':"4.1.0;android;6.0.1;default;A001",
      "HZUID":"2",
    };
  }

DioError [dioerrortype.response]: Http status error [415]

change the request parameter data format FormData to Map< String,dynamic> Try

if you think it will work for you, please click “like” to support it ~ thanks ~