0

i would like to use an endpoint in backend API done with spring boot. the endpoint consist to send an OTP code through email. the endpoint works correctly when i test it but i call him in my flutter application, i have this error : Required String is not present here is a part of the endpoint code :

        @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", 
        value = "Bearer bcryptjwttoken", paramType = 
         "header",required=true),@ApiImplicitParam(name = "Content-Type", 
         value = "application/json", paramType = 
         "header",required=true),
        @ApiImplicitParam(name = "Accept", value = "application/json", 
        paramType = "header",required=true)
         })
       @PostMapping( "/otp/request/{email}")
       public  ResponseEntity<Object> requestOtpPassword(@RequestParam String 
       email) throws AbysterpubFunctionalException {
         try {
          Utilisateur out = userService.requestOtpPassword(email);
         System.out.println("ramses");
         return ResponseEntity.ok(out);
          } catch( AbysterpubFunctionalException afe) {
           return ResponseEntity
                .status(HttpStatus.BAD_REQUEST)
                .body(new ErrorMessage(afe.getMessage()));

         }
          catch (Exception ex) {
                return ResponseEntity
                .status(HttpStatus.INTERNAL_SERVER_ERROR)
                .body(new ErrorMessage(ex.getMessage()));          
           }

          }

and here is the flutter code in which i try to call th endpoint:

           Future<void> requestOtp(String email) {
          RestClient.getAuthToken().then((String token) {
           Map<String, dynamic> postData = {
          "email": email,
           };
          RestClient.procesPostRequest("user/otp/request/$email", postData, 
         token)
         .then((response) {
         print(response);

        if (response == 200) {
        isOTPsent = true;
        } else {
        isOTPsent = false;
        }
       });
       }).catchError((onError) {
       print('$onError');
       return Future.value('error');
      });
      }

          static Future<int> procesPostRequest(String path, Map<String, 
      dynamic> postData,String 
           token) {
        Map<String, String> headers = RestClient.getHeaders(token);

       return http.post("$WS_URL/$path", body: json.encode(postData), 
       headers: headers)
      .then((http.Response response) {
       if (response.statusCode != 200) {
       print(
        "Error while processing post request \n 
       ${WSErrorHandler.fromJson(json.decode(response.body)).toJson()}");
        }
       return response.statusCode;
       });
       }
Ramses Kouam
  • 531
  • 5
  • 14

1 Answers1

0

You are sending the email parameter in the HTTP body but the Spring Boot API expect it as a query parameter in the URL. Here you can see how to send query parameters with Flutter http client: How do you add query parameters to a Dart http request?