[bằng cách sử dụng Apache Tomcat/7.0.27]Rất đặc biệt: HTTP Status 405 - Phương pháp không được phép
Dường như tôi chỉ nhận được lỗi này
- (HTTP Status 405 - Phương pháp không được phép)
khi tôi cố thực hiện yêu cầu REST trực tiếp từ trình duyệt.
ví dụ bằng cách dán này vào thanh địa chỉ:
http://localhost:8080/restExample/rest/catalog/video/14951/hello
Khi tôi chạy client thử nghiệm của tôi Main.java tất cả mọi thứ hoạt động tốt.
Bất kỳ ý tưởng nào về lý do tại sao nó không cho phép tôi thực thi REST thông qua trình duyệt?
Client Side:
public class Main{
public static void main(String [] args){
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI(_package));
runPutRequest(service,"video/128/This is the content with the new description");
}
}
...
private static void runPutRequest(WebResource service,String path){
String response = service.path("rest/catalog/"+path).accept(MediaType.APPLICATION_XML).put(String.class);
System.out.println("Post Response :"+response);
}
Server side:
@PUT
@Path("/video/{video-id}/{short-descr}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_XML)
public Video updateVideo(@PathParam("video-id") int contentid,
@PathParam("short-descr") String descr)
{
//Video video = searchByContentId(contentid);
Video video = videoMap.get(contentid);
video.setDescription(descr);
videoMap.put(contentid,video);
if(videoMap.get(contentid) != null){
return videoMap.get(contentid);
}else{
throw new UnsupportedOperationException("NO object found");
}
}
Đặt vs nhận .... – esej