我想创建一个简单的webservice来生成text/csv内容。但我不能要求它:
@RestController
public class MyServlet {
@PostMapping(produces = {"text/csv", "application/json"})
public Object post() {
//...
}
}
spring.mvc.contentnegotiation.media-types.csv=text/csv当我发送一个以Content-Type: text/csv作为http头的post请求时,我得到了以下错误:
415:Content type 'text/csv' not supported
这是我的配置:
@Configuration
public class ContentNegotiationConfiguration implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer
.favorParameter(true) //favor &format=csv
.defaultContentType(MediaType.APPLICATION_JSON)
.parameterName(format);
//.mediaType("csv", new MediaType("text", "csv")) //also tried without success
}
}发布于 2018-08-14 19:03:07
如果您(客户端)期望csv内容,客户端应该将text/csv作为Accept报头传递,而不是Content-Type。
https://stackoverflow.com/questions/51839422
复制相似问题