【发布时间】:2021-04-07 11:15:52
【问题描述】:
我有一个这样的端点:
@RestController
@RequiredArgsConstructor
@RequestMapping(path = "/api/notifications", produces = APPLICATION_JSON_VALUE)
public class NotificationController {
@PostMapping
@ResponseStatus(value = HttpStatus.CREATED)
public void sendNotification(...) {
...
}
}
在使用协议测试进行测试时,我注意到 api 没有将“application/json”作为 Content-Type 标头返回。我该怎么做呢?
【问题讨论】:
-
它返回的是哪种内容类型?
-
@RequestMapping(value = "/api/notifications", headers = "Accept=application/json, Content-type=application/json") 。这应该适合你
-
您不能将
void设为application/jsonContent-Type,返回一些具有有意义数据的对象,您将获得application/json标头
标签: java spring spring-boot post content-type