【问题标题】:how to put correctly a parameter in an endpoint call with flutter?如何在颤动的端点调用中正确放置参数?
【发布时间】:2020-12-25 08:00:48
【问题描述】:

我想在通过 Spring Boot 完成的后端 API 中使用端点。端点包括通过电子邮件发送 OTP 代码。端点在我测试时工作正常,但我在我的颤振应用程序中给他打电话,我有这个错误:Required String is not present 这是端点代码的一部分:

        @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()));          
           }

          }

这是我尝试调用端点的颤振代码:

           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;
       });
       }

【问题讨论】:

    标签: spring-boot flutter


    【解决方案1】:

    您在 HTTP 正文中发送 email 参数,但 Spring Boot API 期望它作为 URL 中的查询参数。这里可以看到如何使用 Flutter http 客户端发送查询参数:How do you add query parameters to a Dart http request?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      • 2019-05-13
      相关资源
      最近更新 更多