不支持的媒体类型 (415) - PUTting java 列表
当 HTTP 放置列表时,我收到不支持的媒体类型。我的代码如下:
客户端
Client postClient = getClient();
WebResource postWebResource = postClient.resource(DEV_URI+"caches1");
Builder requestBuilder = postWebResource.type(MediaType.APPLICATION_JSON);
requestBuilder.accept(MediaType.APPLICATION_JSON);
requestBuilder.header("accessor", "1011181517");
List<MyEntity> list = new ArrayList<MyEntity>();
MyEntity mapObj = new MyEntity();
mapObj.setId("xxxxxxxxxx");
mapObj.setBookId("xxxxxxxxxxx");
list.add(mapObj);
GenericEntity<List<FacebookEbayMap>> entity = new GenericEntity<List<FacebookEbayMap>>(list) {};
ClientResponse response = requestBuilder.put(ClientResponse.class, entity);
接口
@PUT
@Path("caches1")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response refreshUserCache1(List<MyEntity> userIdMap,
@Context UriInfo uriInfo,
@Context HttpHeaders httpHeaders);
资源
public Response refreshUserCache1(List<MyEntity> userIdMap,
UriInfo uriInfo, HttpHeaders httpHeaders) {
return Response.ok("", MediaType.APPLICATION_JSON).build();
}
我在客户端和服务器端都尝试过使用和不使用 GenericType 。有人可以帮忙吗?
异常
服务器拒绝此请求,因为请求实体的格式不受所请求方法的请求资源支持(不支持的媒体类型)。
I'm getting Unsupported Media Type while HTTP putting a list. My code as follows:
Client
Client postClient = getClient();
WebResource postWebResource = postClient.resource(DEV_URI+"caches1");
Builder requestBuilder = postWebResource.type(MediaType.APPLICATION_JSON);
requestBuilder.accept(MediaType.APPLICATION_JSON);
requestBuilder.header("accessor", "1011181517");
List<MyEntity> list = new ArrayList<MyEntity>();
MyEntity mapObj = new MyEntity();
mapObj.setId("xxxxxxxxxx");
mapObj.setBookId("xxxxxxxxxxx");
list.add(mapObj);
GenericEntity<List<FacebookEbayMap>> entity = new GenericEntity<List<FacebookEbayMap>>(list) {};
ClientResponse response = requestBuilder.put(ClientResponse.class, entity);
Interface
@PUT
@Path("caches1")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response refreshUserCache1(List<MyEntity> userIdMap,
@Context UriInfo uriInfo,
@Context HttpHeaders httpHeaders);
Resource
public Response refreshUserCache1(List<MyEntity> userIdMap,
UriInfo uriInfo, HttpHeaders httpHeaders) {
return Response.ok("", MediaType.APPLICATION_JSON).build();
}
I tried with and without GenericType at both client and server side. Could someone please help here?
Exception
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Unsupported Media Type).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确更新 jar 文件。例如,如果有 3 个名为 A、B 和 C 的应用程序,那么您要在应用程序 A 中导出一个 jar 文件,并在其余应用程序 B 和 C 中导入该文件,这意味着,无论何时,您都必须正确更新这些 jar 文件。正在更改属于 jar 文件的类。
Update the jar files properly. For example, if there are 3 applications named A, B and C then you are exporting a jar file in application A and you are importing that in the remaining applications B and C means, then you have to update the jar files properly, whenever you are changing the classes which belong to the jar file.
确保您的 lib/类路径中有 mimepull.jar。
Make sure you have mimepull.jar in you lib/the classpath.