Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jersey客户端对web服务的请求_Java_Web Services_Rest_Jersey_Jersey Client - Fatal编程技术网

Java 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

我正在尝试通过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.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看到问题了吗