简体   繁体   中英

HTTP Status 405 - Request 'POST' Method Not Allowed

The problem is when i try to call api with @POST notation, i have this error:

HTTP Status 405 - Request  'POST' Method Not Allowed

The other API (@GET) works.

The web.xml is:

<servlet>
        <servlet-name>uJerseyServlet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.fasterxml.jackson.jaxrs;com.info.smarti.api</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>

    </servlet>
   <!-- 
    <servlet-mapping>
        <servlet-name>uJerseyServlet</servlet-name>
        <url-pattern>/app/*</url-pattern>
    </servlet-mapping> -->


      <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
        <async-supported>true</async-supported>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping> 

      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/application-security.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/UsersDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

UPDATE: I try to configure Tomcat with:

 <init-param>
            <param-name>readonly</param-name>
            <param-value>false</param-value>
        </init-param>

but still not work..so the problem is maybe Jersey config..

Example API (POST):

 @Path("/cPass")
    @POST
    @ManagedAsync
    @Consumes(MediaType.TEXT_PLAIN)
    @Produces(MediaType.APPLICATION_JSON)
    public void cPassw(@QueryParam("token") String token,
            @QueryParam("categ") String category,
            @QueryParam("newpass") String newPassword,
            @Suspended final AsyncResponse response) throws Exception {
                       ....
       }

If you are using Tomcat, you have to enable PUT method at server.xml file

Look at http://www.codereye.com/2010/12/configure-tomcat-to-accept-http-put.html

maybe you can check the file which named endwith .java,and you must delete some sentences like "super.doGet(request, response); " or "super.doPost(request, response);" in your methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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