post 使用 dio 调用 api 出现 404 flutter

post calling api using dio gives 404 flutter

我正在从 post 类型的 flutter 中调用 api,但它给我错误 404,可以找出问题所在

class OtpVerifyApi {
  Future otpVerifyAPI(OtpVerifyRequest otpVerifyRequest, String token) async {
    return NetworkCommon.getClient(Constants.apiEndPoint)
        .post("otp",
            data: otpVerifyRequest.toMap(),
            options: new Options(headers: {"Authorization": token}))
        .then((response) {
      return response.data;
    }).catchError((onError) {
      print("onError " + onError.toString());
    });
  }
}

class OtpVerifyRequest {
  String otp;

  toMap() {
    return {"otp": this.otp};
  }
}



verfiyUser(OtpVerifyRequest otpVerifyRequest, String token) async {
    _memoizer.runOnce(() =>
        OtpVerifyApi().otpVerifyAPI(otpVerifyRequest, token).then((reponse) {
          OtpVerifyResponse otpVerifyResponse =
              OtpVerifyResponse.fromJson(reponse);
          print("otpVerifyResponse $otpVerifyResponse");

        }).catchError((error) {
          hideLoader();
          print("otp error: $error");
        }));
  }

这是我的三个源文件,第一个是我的客户端,第二个是我的请求体,第三个是我得到它的响应的地方。 帮我解决这个问题。 提前致谢。

Future<OtpVerifyResponse> verifyUser(
      OtpVerifyRequest otpVerifyRequest, String token) async {
    Map<String, String>  requestHeaders = {
        "Accept": "application/json",
        "Authorization": "Bearer $token",
      };
    return http
        .post(Constants.apiEndPoint + "registration/_verify",
            body: otpVerifyRequest.toMap(), headers: requestHeaders)
        .then((http.Response response) {
      hideLoader();
      final int statusCode = response.statusCode;
      print("statusCode" + statusCode.toString());
      print("response ${json.decode(response.body)}");
      if (statusCode < 200 || statusCode > 400 || json == null) {
        hideLoader();
        throw new Exception("Error while fetching data");
      }
      return OtpVerifyResponse.fromJson(json.decode(response.body));
    });
  }

我也试过这种 http 方法,但它也不起作用不知道我做错了什么

class OtpVerifyApi {
  Future otpVerifyAPI(OtpVerifyRequest otpVerifyRequest, String token) async {
    return NetworkCommon.getClient(Constants.apiEndPoint)
        .post("otp",
            data: otpVerifyRequest.toMap(),
            options: new Options(headers: {"Authorization": "Bearer $token"}))
        .then((response) {
      return response.data;
    }).catchError((onError) {
      print("onError " + onError.toString());
    });
  }
}

我以错误的方式传递授权令牌..花了一段时间才弄明白:)