我正在尝试使用
post
请求从我的 Spring-Boot 应用程序访问 swagger URL。但是得到一个 400-Bad request
并显示 请求正文丢失。但同样的请求在 Postman 中工作得很好。
控制器:
@RestController
public class IdVController {
@Autowired
private IdService idService;
@Autowired
protected FileUtility util;
/** The Constant STATUS. */
private static final String STATUS = "status";
/** The Constant SUCCESS. */
private static final String SUCCESS = "success";
/** The Constant SYSTEM. */
private static final String SYSTEM = "SYSTEM";
@RequestMapping(value ="/idApi")
public ResponseEntity<MarketPlaceResponse>
validateIdData(@RequestBody VerifyIdDTO verifyIdDTO) throws Exception {
JSONObject rawResponse = idService.validateId(verifyIdDTO);
IdVerifyEntity DTOResponse = (IdVerifyEntity)util.convertToEntity(rawResponse.toString(), IdVerifyEntity.class);
if (rawResponse.get(STATUS).equals(SUCCESS)) {
DTOResponse.setCreated_by(SYSTEM);
DTOResponse.setCreated_date(new
java.sql.Date(System.currentTimeMillis()).toString());
}
//return ResponseBuilder.buildResponse(DTOResponse);
MarketPlaceResponse response = new MarketPlaceResponse();
response.setResponse(DTOResponse);
return new ResponseEntity<MarketPlaceResponse>(response,HttpStatus.OK);
}
}
请求DTO:
public class VerifyIdDTO {
@NotBlank(message="Owner ID should not be empty")
private String id;
private String citizenship;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCitizenship() {
return citizenship;
}
public void setCitizenship(String citizenship) {
this.citizenship = citizenship;
}
}
我通过构建 URL 并使用此 POST 方法中的 GET 来联系外部服务 这是 swagger 的 URL
localhost:8080/idvalidationservice/swagger-ui.html
您可以在此屏幕截图中看到错误消息。
你解决了吗? 如果是的话怎么办?