春・ウェブサーブレットにコンテンツタイプとしてテキスト/ CSVを受け入れるするには?

membersound:

私が作成し、単純なWebサービスを作成したい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ヘッダとして、私は次のエラーを取得しています:

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
    }
}
Reithの:

あなたは(クライアント)のCSVコンテンツを期待している場合、クライアントは合格しなければならないtext/csvようAcceptではないヘッダーContent-Type

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=210077&siteId=1
おすすめ