简体   繁体   English

DioError [DioErrorType.response] Http 状态错误 [404] - flutter

[英]DioError [DioErrorType.response] Http status error [404] - flutter

 DioError [DioErrorType.response] Http status error [404] - flutter 

I'm creating a forget password screen for my app.我正在为我的应用程序创建一个忘记密码屏幕。 I want to display "email sent" message when I click "Reset password " button.. instead of that,I'm getting above error when I'm enter already registered email address.当我单击“重置密码”按钮时,我想显示“电子邮件已发送”消息。相反,当我输入已经注册的 email 地址时,我遇到了上述错误。 postman request is successfully working. postman 请求已成功运行。 how to solve this issue.如何解决这个问题。 appreciate your help on this.感谢您对此的帮助。

邮递员回复

   import 'package:dio/dio.dart';
import 'package:doctor_app/constants/Button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import '../constants/colors.dart';

class ForgetPassword extends StatelessWidget {
  const ForgetPassword({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.leanBack);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Padding(
        padding: const EdgeInsets.all(20.0),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                SizedBox(
                  height: 20,
                ),
                Text('DOCTOR',
                    style: TextStyle(
                      fontFamily: 'Dubai',
                      fontSize: 30,
                      color: Color(0xff05ABA3),
                      fontWeight: FontWeight.w500,
                    )),
              ],
            ),
            Spacer(
              flex: 1,
            ),
            Row(mainAxisAlignment: MainAxisAlignment.start, children: [
              Text('Forgot your password?',
                  style: TextStyle(
                    height: 1.2,
                    fontFamily: 'Dubai',
                    fontSize: 25,
                    color: Color(0xff040000),
                    fontWeight: FontWeight.w500,
                  )),
            ]),
            Spacer(
              flex: 1,
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text('Confirm your email and we will send the Instructions ',
                    style: TextStyle(
                      height: 1.2,
                      fontFamily: 'Dubai',
                      fontSize: 18,
                      color: Color(0xff707070),
                      fontWeight: FontWeight.w100,
                    )),
              ],
            ),
            Spacer(
              flex: 1,
            ),

            ForgetPasswordForm(), //email
            Spacer(
              flex: 1,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  'didnt receive an email?',
                  style: TextStyle(
                    height: 1.2,
                    fontFamily: 'Dubai',
                    fontSize: 13,
                    color: Colors.grey,
                    fontWeight: FontWeight.w500,
                  ),
                ),
                SizedBox(
                  width: 5,
                ),
                Align(
                    alignment: Alignment.bottomLeft,
                    child: InkWell(
                        onTap: () {
                          // add action here whatever you want.
                        },
                        child: Text('send again  ',
                            style: TextStyle(
                              height: 1.2,
                              fontFamily: 'Dubai',
                              fontSize: 13,
                              color: Colors.blue,
                              fontWeight: FontWeight.w500,
                            ))))
              ],
            ),
            Spacer(
              flex: 1,
            ),

            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5.0),
                    color: Color(0xff05ABA3),
                  ),
                  height: 5,
                  width: 120,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class ForgetPasswordForm extends StatefulWidget {
  const ForgetPasswordForm({Key? key}) : super(key: key);

  @override
  _ForgetPasswordFormState createState() => _ForgetPasswordFormState();
}

class _ForgetPasswordFormState extends State<ForgetPasswordForm> {
  final _formKey = GlobalKey<FormState>();

  //String _userName = "";
  String email = "";

  Future Resetpassword() async {
    try {
      var response = await Dio().post(
          'https://doctor-app2-hit.herokuapp.com/user/forgotpassword',
          data: {
            "email": email,
          });

      if (response.data["data"] ==
          "Please check your email to reset password.") {
        Get.snackbar("success", "Email Sent Successfully!");
        //Get.to(VideoScreen());

      }else{
        Get.snackbar("error", "No User Found");
      }
      print("res: $response");
    } catch (e) {

      Get.snackbar("error", "Server Error");
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Form(
            child: Container(
                key: _formKey,
                child: Container(
                    child: Padding(
                  padding: const EdgeInsets.all(30.0),
                  child: Column(children: [
                    TextFormField(
                        keyboardType: TextInputType.emailAddress,
                        decoration: const InputDecoration(
                            hintText: "Email",
                            hintStyle: TextStyle(
                                color: textGrey,
                                fontFamily: "Dubai",
                                fontSize: 14)),
                        validator: (String? Email) {
                          if (Email != null && Email.isEmpty) {
                            return "Email can't be empty";
                          }
                          return null;
                        }),
                    SizedBox(
                      height: 50,
                    ),
                    Container(
                      child: GestureDetector(
                        child: ButtonM("Reset Password"),
                        onTap: () async {
                          Resetpassword();
                        },
                      ),
                    )
                  ]),
                )))));
  }
}

404 is thrown since the endpoint you are trying to call cannot be found.抛出 404,因为找不到您尝试调用的端点。 Notice that the URL you try to call has two forward slashes before the user path.请注意,您尝试调用的 URL 在user路径前有两个正斜杠。

Change this: https://doctor-app2-hit.herokuapp.com//user/forgotpassword to this: https://doctor-app2-hit.herokuapp.com/user/forgotpassword改变这个: https://doctor-app2-hit.herokuapp.com//user/forgotpassword到这个: https://doctor-app2-hit.herokuapp.com/user/forgotpassword

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DioError [DioErrorType.RESPONSE]:Http 状态错误 [404] - DioError [DioErrorType.RESPONSE]: Http status error [404] Flutter:DioError [DioErrorType.RESPONSE]:Http 状态错误 [500] - Flutter: DioError [DioErrorType.RESPONSE]: Http status error [500] Flutter DioError [DioErrorType.RESPONSE]: Http 状态错误 [403] - Flutter DioError [DioErrorType.RESPONSE]: Http status error [403] Flutter Dio:DioError [DioErrorType.RESPONSE]:Http 状态错误 [429] - Flutter Dio : DioError [DioErrorType.RESPONSE]: Http status error [429] I/flutter (28276):此处发现错误 DioError [DioErrorType.response]:Http 状态错误 [404] - I/flutter (28276): Error found Here DioError [DioErrorType.response]: Http status error [404] DioError [DioErrorType.RESPONSE]: Http 状态错误 [400] 异常 - DioError [DioErrorType.RESPONSE]: Http status error [400] Exception DioError [DioErrorType.RESPONSE]:Http 状态错误 [500],为什么? - DioError [DioErrorType.RESPONSE]: Http status error [500], why? 无法捕获 dioerror [dioerrortype.response]:http 状态错误 [statusCode] - Unable to catch dioerror [dioerrortype.response]: http status error [statusCode] DioError [DioErrorType.RESPONSE]: Http 状态错误 [405] [已解决] - DioError [DioErrorType.RESPONSE]: Http status error [405] [Solved] DioError [DioErrorType.response]:Http 状态错误 [401] - DioError [DioErrorType.response]: Http status error [401]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM