繁体   English   中英

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

[英]@PUT Jersey Error 405: Method not allowed

我正进入(状态

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

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

您应该使用适当的REST客户端才能创建PUT请求。 我正在使用的一个很好的是Chrome的Postman扩展程序: 链接

出现上述错误的原因是,您正在尝试将GET请求发送到/ sendvalue,并且此方法/路径对未映射任何内容。

甚至我都在忙着使用浏览器发送POST请求! 您可以使用POSTMAN chrome客户端测试POST请求。 (为此,您可以将POSTMAN用于所有http方法)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM