我正进入(状态
错误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,并且该方法/路径对未映射任何内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句