title: Curl POST request for spring mvc gives 405 Method 'POST' not supported
body: <p>I have a SPRING 4 application. It authenticates using Spring Security Ldap authentication. All works, but when I try to do a POST request it fails giving me a <strong>WARN : org.springframework.web.servlet.PageNotFound - Request method 'POST' not supported.</strong></p>
  
  <p>I am trying to do a post request using a curl command in my script which triggers the controller's POST method and upload a file.</p>
  
  <p>spring-security.xml </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:security="http://www.springframework.org/schema/security"
      xsi:schemaLocation="http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
  
      &lt;security:http auto-config="true" use-expressions="true"&gt;
        &lt;security:intercept-url pattern="/login" access="permitAll()" /&gt;
  
  
  
  
        &lt;security:intercept-url pattern="/info"  access="permitAll()" method="GET" /&gt;
        &lt;security:intercept-url pattern="/bookings" access="isAuthenticated()" method="POST"/&gt;
  
        &lt;security:intercept-url pattern="/chartdata"    access="isAuthenticated()" method="GET" /&gt;
        &lt;security:intercept-url pattern="/uploadData/*" access="isAuthenticated()" method="POST"/&gt; &lt;!-- Change2 --&gt;
    &lt;security:intercept-url pattern="/**"     access="isAuthenticated()" /&gt;
  
        &lt;security:form-login login-page="/login"
          login-processing-url="/performLogin"
          authentication-failure-url="/login?error=true" /&gt;
        &lt;access-denied-handler error-page="/login" /&gt;
      &lt;/security:http&gt;
  
  
      &lt;security:authentication-manager alias="authenticationManager"&gt;
          &lt;security:ldap-authentication-provider  user-dn-pattern="uid={0}, ou=People,o=XXX" /&gt;
      &lt;/security:authentication-manager&gt;
  
      &lt;ldap-server url="ldap://ldap.xxx.com/dc=xxx,dc=com" port="389" /&gt;
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Controller.java</p>
  
  <pre><code>@RequestMapping(value = "/uploadData/{type}****?${_csrf.parameterName}=${_csrf.token}****", headers = {"Accept=*/*","enctype=multipart/form-data"}, method = {RequestMethod.POST, RequestMethod.GET }, consumes="*/*")
  public String uploadData_type( //
          @PathVariable("type") final String type, //
          @RequestParam("theDate") final String theDate, //        
          @RequestParam("data") final MultipartFile theFile //
          ) {
      String status_message = null;
      Tracking.message("Importing '%s' file: '%s'", type, theFile.getOriginalFilename());
       ..........
  }
  </code></pre>
  
  <p>type,theDate and data are passed from the script once the script does the curl call.</p>
  
  <p>Script code: </p>
  
  <pre><code>#!/bin/bash
  
  SILENT=--silent
  
  THIS_SCRIPT=${0##*/}
  
  FILETYPE=$1
  theFile=$2
  theFileName=${theFile##*/}
  theDate=${theFileName##*.}
  
  URL="http://localhost:8080/gds-report/uploadData/$FILETYPE"
  
  msg=$(curl $SILENT -X POST  -F "data=@$theFile" -F "theDate=$theDate" -F "filename=$theFileName"  -H "Content-Type: multipart/form-data"  "$URL")
  echo -n $THIS_SCRIPT: 
  if [ -z "$msg" ] ; then
     echo "Results - no message received"
     exit 1
  else
     echo "Results: $msg"
  fi
  </code></pre>
  
  <p>I have tried 2 solutions I found on stackoverflow: 
  1) editing and trying with the passing of csrf parameters in the request or changing the method type disabling csrf . But, no luck, it always gives me a 405 Error.
  2) Adding this bean in my app-servlet.xml file for allowing files of large size to be uploaded. </p>
  
  <pre><code>&lt;beans:bean id="multipartResover"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
          &lt;beans:property name="maxUploadSize" value="2000000"&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  </code></pre>
  
  <p>I tried to debug using curl for windows and POSTMAN both give the same error. i cannot find something more about this on any documentation. Can someone please help, I think it is something very minor I am missing.</p>
  
  <p>POSTMAN ERROR OUTPUT below shows a <strong>Allow: GET</strong> header which I do not understand why it comes up even though I request using POST method and response header has Allow:GET only.</p>
  
  <pre><code>Allow → GET
  Cache-Control → no-cache, no-store, max-age=0, must-revalidate
  Content-Language → en
  Content-Length → 1090
  Content-Type → text/html;charset=ISO-8859-1
  Date → Thu, 25 Feb 2016 08:54:26 GMT
  Expires → 0
  Pragma → no-cache
  Server → Apache-Coyote/1.1
  X-Content-Type-Options → nosniff
  X-Frame-Options → DENY
  X-XSS-Protection → 1; mode=block
  </code></pre>
  
  <p>NOTE: The GET requests in the Controller are successfully completed. just the POST don't work at all.Please suggest me something. Spring 4. Java 8 Tomcat 8.</p>