Java Jersey客户端对web服务的请求
我正在尝试通过jersey客户端请求web服务:Java Jersey客户端对web服务的请求,java,web-services,rest,jersey,jersey-client,Java,Web Services,Rest,Jersey,Jersey Client,我正在尝试通过jersey客户端请求web服务: 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.cl
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
请注意url路径http://localhost:8080/jersey-示例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))代码>
您只生成文本,但请求媒体类型应用程序\u JSON(通过accept标头),这就是为什么您得到响应,即请求不可接受。意思是,您在响应中返回的数据不在媒体类型。应用程序\u JSON
中。检查生成输出的方法。显示端点方法的代码。@CássioMazzochiMolin看到问题了吗