我想回来, 555 status code in response .
我已经检查了Spring框架的ResponseEntity类 .
我可以看到所有构造函数只接受来自HttpStatus枚举的特定代码 . 这可以通过以下方式实现:
return ResponseEntity.status(HttpStatus.CREATED).contentType(MediaType.TEXT_PLAIN).body("Custom string answer");
Is there any way to return status code like 555?
2 回答
你不能使用Spring
ResponseEntity
来做到这一点 .但你可以随时掌握底层的
HttpServletResponse
并做一个response.setStatus(555)
.作为旁注,如果您的问题是"is it OK to return non-standard HTTP codes in this scenario?",答案可能是"no" .
你可以在Spring做到: