相关疑难解决方法(0)

无法向基于Spring MVC的REST服务发送多部分/混合请求

我有一个基于Spring MVC和Resteasy的REST服务,我需要通过发送multipart/mixed请求进行测试.

该服务编码如下:

@POST
    @Path("/mixedMimeText")
    @Consumes("multipart/mixed")
    @ResponseStatus(HttpStatus.OK)
    public String createMime(@Context ServletContext servletContext, MultipartInput input) throws Exception, IOException {

        logger.info("Processing /mixedMimeText");

        for(InputPart p : input.getParts()){
            logger.info("Headers : " + p.getHeaders());
            logger.info("MediaType : " + p.getMediaType());
            logger.info("Body : " +  p.getBodyAsString());
            logger.info("--------------------------------------------------- ");
        }

        return "TEST";
    }
Run Code Online (Sandbox Code Playgroud)

我使用以下文件作为multipart mime内容发送

--ABC123Boundary
Content-Type: text/xml

<?xml version="1.0" ?>
<request>
<account-id>XXXX-XXXX-XXXX-XXXX</account-id>
<reference>12345</reference>
<app-name>XXXXXXXXX</app-name>
<information>
<calling-party>
<name>Joe Bloggs</name>
<identifier>441234567890</identifier>
</calling-party>
<called-party>
<name>John Smith</name>
<identifier>15551234567</identifier>
</called-party>
</information>
</request>

--ABC123Boundary
Content-Type: text/xml

UklGRkBAAABXQVZFZm10IBAAAAAHAAEAQB8AAEAfAAABAAgAZmFjdAQAAAAPQ
AAAZGF0YRBAAABn5///////////////5///Z+fn///n////////5////////2f//2f//+f//+f////n/
///////52f//////2f//////2f/////5////////+f/////Z+f///////////////9n//9nZ/9n////5+f///9
<snip>
//+f//////2f/////////5//n//////////9n

--ABC123Boundary--
Run Code Online (Sandbox Code Playgroud)

我使用curl客户端使用以下命令发送请求: …

java spring curl spring-mvc

11
推荐指数
1
解决办法
3万
查看次数

标签 统计

curl ×1

java ×1

spring ×1

spring-mvc ×1