我正在尝试使用 Jersey Library 构建一个 REST API。API 中的 Post 方法应该使用 JSON 正文。当我尝试通过 Postman 发送请求时,我收到 405 错误。
@POST
@Path("CreateADGroup")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/json")
@RequiredRight(value = "createADGroup")
public Map postCreateADGroup(RequestValues requestValues) {
log.debug("POST CreateADGroup");
log.debug("This is the value" + requestValues.getValue());
// using a test map untill i can get the actual values.
Map ret = new HashMap();
ret.put("Val", "TestVal");
return ret;
}
这是POJO方法
public class RequestValues {
String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
我曾尝试使用 Direct JsonObject 初始化,但我收到了同样的错误。
@POST
@Path("CreateADGroup")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/json")
@RequiredRight(value = "createADGroup")
public Map postCreateADGroup(JSONObject requestValues) {
Map ret = new HashMap();
ret.put("Val", "TestVal");
return ret;
}
沧海一幻觉
相关分类