3
我有問題jax-rs服務,服務返回HTTP狀態405 - 方法不允許。 我從android項目調用serice。HTTP狀態405 - 不允許的方法(jax-rs服務)
這裏是我的代碼:
服務:
@GET
@Consumes(MediaType.TEXT_HTML)
@Produces(MediaType.APPLICATION_JSON)
@Path("login")
public Korisnici Login(@QueryParam("u") String username,@QueryParam("p") String password){
Korisnici exception = new Korisnici();
try {
for (Korisnici obj : KorisniciDAO.getInstance().getAll()) {
if (obj.getUsername().equals(username)
&& obj.getPassword().equals(password)) {
return obj;
}
}
return new Korisnici();
} catch (Exception e) {
exception.setIme(e.toString());
return exception;
}
}
代碼在android系統:
public static Boolean Login(Korisnici k) {
String url = "http://myserver.com/AndroidServis/rest/korisnik_servis/login?u={u}&p={p}";
restTemplate = new RestTemplate();
headers = new HttpHeaders();
//headers.set("Accept", "application/json");
headers.setContentType(MediaType.APPLICATION_JSON);
params = new HashMap<String, String>();
params.put("u", k.getUsername().toString());
params.put("p", k.getPassword().toString());
entity = new HttpEntity(headers);
restTemplate.getMessageConverters().add(
new GsonHttpMessageConverter());
restTemplate.getMessageConverters().add(
new StringHttpMessageConverter());
HttpEntity<Korisnici> response = restTemplate.exchange(
url, HttpMethod.GET, entity,
Korisnici.class, params);
}
我不知道在哪裏的問題。