代码之家  ›  专栏  ›  技术社区  ›  Aparna Savant

@PUT Jersey错误405:不允许使用方法

  •  1
  • Aparna Savant  · 技术社区  · 10 年前

    我得到了

    错误405:不允许使用方法

    消息结束.java:

    package com.example.wordcount;
    
    import javax.ws.rs.Consumes;
    import javax.ws.rs.GET;
    import javax.ws.rs.PUT;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.core.Response;
    
    @Path("/jersey")
    public class MessageEnd {
    
        @GET
        @Path("/getvalue/{word}")
        @Produces(MediaType.TEXT_PLAIN)
        public Response sayHello(@PathParam("word") String word){
    
            String output = " Count of word " + word;
            return Response.status(200).entity(output).build();
        }
    
        @PUT
        @Path("/sendvalue/{msg}")
        @Consumes(MediaType.TEXT_PLAIN)
        @Produces(MediaType.TEXT_PLAIN)
        public Response sendMsg(@PathParam("msg") String msg){
    
            String output = "Received message= " + msg;
            return Response.status(200).entity(output).build();
        }
    
    }
    

    FYI, @GET 工作正常。

    我正在使用以下URI:

    http://localhost:8080/message/jersey/sendvalue/hi
    
    2 回复  |  直到 5 年前
        1
  •  6
  •   dimoniy    10 年前

    您的浏览器仅发送 GET 在地址栏中键入任何内容时请求。您可以在这里了解HTTP方法之间的区别: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods

    您应该使用适当的REST客户端来创建 PUT 请求。我正在使用的一个非常好的是Chrome的Postman扩展: link

    出现上述错误的原因是您试图发送 获取 请求到/sendvalue,并且没有为该方法/路径对映射任何内容。

        2
  •  0
  •   Binita Bharati    9 年前

    甚至我也在搞怪,用浏览器发送POST请求!您可以使用POSTMAN chrome客户端来测试POST请求。(为此,您可以对所有http方法使用POSTMAN)