Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么在POST请求中不允许使用HTTP 405方法?_Java_Rest_Post_Httprequest_Tomcat8 - Fatal编程技术网

Java 为什么在POST请求中不允许使用HTTP 405方法?

Java 为什么在POST请求中不允许使用HTTP 405方法?,java,rest,post,httprequest,tomcat8,Java,Rest,Post,Httprequest,Tomcat8,我正在使用JAX-RS,在我的web服务中有以下POST方法: @Path("create") public class Create { public Create() { } @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public PostBundle createNewUser(final UserCredentia

我正在使用JAX-RS,在我的web服务中有以下POST方法:

@Path("create")
public class Create {

    public Create() {

    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public PostBundle createNewUser(final UserCredentials userCredentials) {

        final String name = userCredentials.getName();
        final String mobile = userCredentials.getMobile();
        final String password = userCredentials.getPassword();

        if  (mobile != null && password != null) {
            PostManager postManager = new PostManager();
            Response response = postManager.createUserByMobile(name, mobile, password);

            if  (response.getStatus() == Status.ALREADY_EXISTS)
                return new PostBundle("409","Conflict",null);
            else if (response.getStatus() == Status.SUCCESS) {
                return postManager.getPostBundleByMobile(name, mobile, password);
            } else
                return new PostBundle("500",response.getMessage(),null);

        } else {
            return new PostBundle("400", "BAD REQUEST",null);
        }

    }
}
我有如下UserInfo.java

public class UserCredentials {

    private String name;
    private String email;
    private String mobile;
    private String password;

    public UserCredentials() {

        name = null;
        email = null;
        mobile = null;
        password = null;

    }

//Usual getters and setters

............

}
我正在使用Chrome的Postman,并通过POST请求发送以下JSON

{
    "name"      :   "Arijit Banerjee",
    "email"     :   "",
    "mobile"    :   "0123456789",
    "password"  :   "65656565"
}
我得到一个不允许的HTTP 405方法。我不明白为什么。我遵循了在线教程(),查看了给出的建议,但没有任何效果。我正在Apache Tomcat 8上运行我的Web服务。

您尝试过:

@XmlRootElement
public class UserCredentials {

    private String name;
    private String email;
    private String mobile;
    private String password;

    public UserCredentials() {

        name = null;
        email = null;
        mobile = null;
        password = null;

    }

//Usual getters and setters

............

}
您是否尝试过:

@XmlRootElement
public class UserCredentials {

    private String name;
    private String email;
    private String mobile;
    private String password;

    public UserCredentials() {

        name = null;
        email = null;
        mobile = null;
        password = null;

    }

//Usual getters and setters

............

}

您正在使用哪个web框架?因为,呃,该URL上不允许使用POST方法。与你发布的代码无关。那么我该如何处理这个问题?这是否意味着我永远无法向我刚刚在Heroku上制作的web应用程序发出发布请求?如果你遵循该教程,我猜你将有一个
MessageResource
类。你能给我们看一下它的代码吗?你使用的是哪个web框架?因为,呃,在那个URL上不允许使用POST方法。与你发布的代码无关。那么我该如何处理这个问题?这是否意味着我永远无法向我刚刚在Heroku上制作的web应用程序发出发布请求?如果你遵循该教程,我猜你将有一个
MessageResource
类。你能给我们看看它的代码吗?我正在使用JAX-RS,这会有帮助吗?你试过了吗?为什么?有什么不同,它会有什么帮助?我正在使用JAX-RS,会有帮助吗?你试过了吗?为什么?什么是不同的,它将如何帮助?