gpt4 book ai didi

java - 未找到 com.sun.jersey.core.util.MultivaluedMapImpl 类和 MIME 媒体类型 application/json

转载 作者:行者123 更新时间:2023-12-01 12:32:59 24 4
gpt4 key购买 nike

这是我的测试

final Client client = Client.create();
final WebResource webResource = client.resource(ORDER_API);
final MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
formData.add("name", "Autobot-00");
formData.add("resExpiryKey", "19000");

final ClientResponse response = webResource.type(MediaType.APPLICATION_JSON)
.header("Content-Type", MediaType.APPLICATION_JSON).post(ClientResponse.class, formData);
assertEquals(response.getStatus(), 200);

我的 pom.xml 看起来像

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
<scope>test</scope>
</dependency>

当我运行测试时,我看到以下内容

com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl, and MIME media type, application/json, was not found
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)

缺少什么?

最佳答案

当您使用 MultivaluedMap 时,您应该使用

.type(MediaType.APPLICATION_FORM_URLENCODED)
而不是
.type(MediaType.APPLICATION_JSON)

关于java - 未找到 com.sun.jersey.core.util.MultivaluedMapImpl 类和 MIME 媒体类型 application/json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25798308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com