Jax-rs 服务返回HTTP 状态 405 - Method Not Allowed。
服务:
@GET
@Consumes(MediaType.TEXT_HTML)
@Produces(MediaType.APPLICATION_JSON)
@Path("login")
public User Login(@QueryParam("u") String username, @QueryParam("p") String password) {
return UserDAO.getInstance().getLogin(username,password)
}
安卓:
public static Boolean Login(User user) {
String url = "http://myserver.com/AndroidServis/rest/login?u={u}&p={p}";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HashMap<String, String> params = new HashMap<String, String > ();
params.put("u", user.getUsername().toString());
params.put("p", user.getPassword().toString());
HttpEntity entity = new HttpEntity(headers);
restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
HttpEntity < Korisnici > response = restTemplate.exchange(url, HttpMethod.GET, entity,User.class, params);
}