泽西岛动态地打开内容类型 [英] Jersey switch on Content Type dynamically
问题描述
一个类似的问题在这里:同时支持这两种方式和在新泽西州的应用程序网址编码参数
A similar question is here: Supporting both Multipart and Application Url Encoded parameters in Jersey
我有一个API端点(位于Jersey),可以接受POST请求.内容类型为:表单编码或多部分.两种类型的请求到达相同的路径.我该如何打开?
I have an API endpoint (in Jersey) that can accepts POST request. The content types are either: form-urlencoded, or multipart. The two types of request arrive at the same path. How do I switch on that?
对于urlencoded请求,我想获取参数:
For the urlencoded request, I want to get argument:
@FormParam("recipient") String recipient
对于多部分请求,我想获得:
For multipart request, I want to get:
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail
谢谢!
推荐答案
我认为Jersey仅对每个唯一的@Path
& @VERB
对,这意味着您要么需要使其中之一使用不同的动词(POST和PUT),要么需要两条不同的路径.在您进行一个POST和另一个PUT之前,请确保您了解如何正确使用动词在REST中.
I think that Jersey only allows a single method for each unique @Path
& @VERB
pair, meaning that you'll either need to have one of those things use a different verb (POST and PUT) or you need two different paths. Before you just go and make one POST and the other PUT, make sure you understand how to properly use verbs in REST.
这篇关于泽西岛动态地打开内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!