【问题标题】:@PUT Jersey Error 405: Method not allowed@PUT Jersey 错误 405:方法不允许
【发布时间】:2014-10-04 21:54:25
【问题描述】:

我来了

错误 405:方法不允许

MessageEnd.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();
    }

}

仅供参考,@GET 工作正常。

我正在使用以下 URI:

http://localhost:8080/message/jersey/sendvalue/hi

【问题讨论】:

  • PUT 做得怎么样?显示您的客户代码(如果有)
  • 我没有任何客户端代码,我通过 URI 发送参数。 (如果我做错了什么请纠正我)

标签: java http tomcat jersey put


【解决方案1】:

即使我在搞砸,使用浏览器发送 POST 请求!您可以使用 POSTMAN chrome 客户端来测试您的 POST 请求。 (就此而言,您可以将 POSTMAN 用于所有 http 方法)

【讨论】:

    【解决方案2】:

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

    您应该使用正确的 REST 客户端来创建 PUT 请求。我正在使用并且相当不错的是 Chrome 的 Postman 扩展:link

    上述错误的原因是您尝试向 /sendvalue 发送 GET 请求,但没有为该方法/路径对映射任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      相关资源
      最近更新 更多