@Path("postUser") public class PostUser { @POST @Produces(MediaType.TEXT_XML) public String postUser(){ return "涛哥"; } @Path("bean") @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON}) public User postUser(@FormParam("username") String username){ User user = new User(); System.out.println(username); user.setUsername(username); user.setPassword("涛哥"); return user; } } public class PostUser { /** * @param args * @throws UnsupportedEncodingException */ public static void main(String[] args) throws UnsupportedEncodingException { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); MultivaluedMap<String, String> param = new MultivaluedMapImpl(); param.add("username", "ssss"); System.out.println(service.path("services").path("postUser") .path("bean").queryParams(param) .type(MediaType.APPLICATION_FORM_URLENCODED).post(String.class)); } private static URI getBaseURI() { return UriBuilder.fromUri( "http://localhost:8080/jersey/").build(); } // 注意 .type(MediaType.APPLICATION_FORM_URLENCODED). type 而不是 accept 否则将出错的