I / flutter(23942):DioError [DioErrorType.RESPONSE]:Http状态错误[500]

时间:2020-03-12 04:41:21

标签: flutter dart http-error dio

我在通过API进行身份验证或登录时遇到HTTP错误500。 并且无法得到此错误。 之前效果很好,但是突然抛出了这个HTTP错误。

代码:

Dio类的实例:

dio() {
    Dio dio = Dio();

    dio.options.connectTimeout = 60000; //5s
    dio.options.receiveTimeout = 60000;
    return dio;
  }

身份验证方法

Future<Map> authenticate({@required String username, @required String password}) async{
   String url =  "https://.....";
   Response response;
   try{
     response =await dio().post(
       url,
       options: Options(
         contentType: ContentType.parse("application/x-www-form-urlencoded"),
       ),

       data: {
         'grant_type': 'password',
         'client_id':clientId,
         'client_secret':clientSecret,
         'username': username,
         'password': password,
       }
     );
     print("Authentication post response.dataaaaaa:${response.data}");
     return response.data;

   }catch(e){
     print("ERROR:$e");
     throw e;
   }
 }

在catch组中出错:

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

1 个答案:

答案 0 :(得分:0)

Http状态码500表示您的API后端有问题吗?