DioError [DioErrorType.response]: Http 状态错误 [400]

问题描述

我在 dio 数据参数中传递文本框(用户名和密码)的值,但它给了我 http 400 错误

这是我的 dio 代码

class AuthService{
  dio dio=new dio();
var localhost_url="http://192.168.1.102:5000/login";
var heroku_Url="https://attendance-demo.herokuapp.com/login";
 
  login(name,password) async{
    Map<String,dynamic> data={
      'username':name,'password':password
    };
await dio
        .post(heroku_Url,data: json.encode(data))
          .then((onResponse){
            print(onResponse.data);
          }).catchError((onerror){
            print(onerror.toString());
        });

  }
}

在这里调用按钮点击的 dio 请求

RoundedButton(text:"Login",press: () {
 AuthService().login(name,password).then((value){
                       if(value.data['success']){
                         token=value.data['token'];
                         Fluttertoast.showToast(msg: 'Authenticated',toastLength: Toast.LENGTH_SHORT,gravity: ToastGravity.BottOM,backgroundColor: Colors.red,textColor: Colors.white,fontSize: 16.0);
                    }
                  
                  });   
                       
                    }
                  ),

我对 localhost 使用相同的代码并且它运行良好,但是当我使用 Atlas-mongodb 和 heroku url 时它会打印 400 错误

请帮助修复它!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)