[英]Jersey client request to web-service
我正在尝试通过球衣客户端请求网络服务:
WebResource service = client.resource(UriBuilder.fromUri("http://localhost:8080/jersey-example-new/").build());
System.out.println(service.path("rs/").path("account/details/1").accept(MediaType.APPLICATION_JSON).get(String.class));
但我得到:
GET http://localhost:8080/jersey-example-new/rs/account/details/1 returned a response status of 406 Not Acceptable
请注意,网址路径http://localhost:8080/jersey-example-new/rs/account/details/1
在浏览器中有效。 java客户端请求有什么问题?
端点代码:
@Path("account")
public class AccountDetailsService {
@GET
@Path("/details/{param}")
@Produces(MediaType.TEXT_PLAIN)
public Response getAccountDetails(@PathParam("param") String accountName) {
String output = "Account Name : " + accountName;
return Response.status(200).entity(output).build();
}
}
你应该改变
System.out.println(service.path("rs/").path("account/details/1").accept(MediaType.APPLICATION_JSON).get(String.class));
到System.out.println(service.path("rs/").path("account/details/1").accept(MediaType.TEXT_PLAIN).get(String.class));
您仅生成 TEXT_PLAIN,但您请求媒体类型 APPLICATION_JSON(通过接受标头),这就是您得到响应的原因,该请求是不可接受的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.