【发布时间】: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