Jax-rs服务返回HTTP状态码405 - 不允许的方法。
服务:
服务:
@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);
}