2

I have my backend with spring mvc and my frontend with sencha touch, I want to send an image in base 64 through POST using Ajax.Request.

But I get the following error:

XMLHttpRequest cannot load http://ip:port/projectname/method?  The request was redirected to '', which is disallowed for cross-origin requests that require preflight.

I am using cors-filter with manven

<dependency>
    <groupId>com.thetransactioncompany</groupId>
    <artifactId>cors-filter</artifactId>
    <version>1.9.2</version>
</dependency>

My web.xml

    <filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

        <init-param>
            <param-name>cors.allowGenericHttpRequests</param-name>
            <param-value>true</param-value>
        </init-param>

        <init-param>
            <param-name>cors.allowOrigin</param-name>
            <param-value>*</param-value>
        </init-param>

        <init-param>
            <param-name>cors.allowSubdomains</param-name>
            <param-value>false</param-value>
        </init-param>

        <init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET, HEAD, POST, OPTIONS</param-value>
        </init-param>

        <init-param>
            <param-name>cors.supportedHeaders</param-name>
            <param-value>*</param-value>
        </init-param>   

        <init-param>
            <param-name>cors.supportsCredentials</param-name>
            <param-value>true</param-value>
        </init-param>

        <init-param>
            <param-name>cors.maxAge</param-name>
            <param-value>3600</param-value>
        </init-param>

</filter>

        <filter-mapping>
            <!-- CORS Filter mapping -->
            <filter-name>CORS</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

My Ajax.Request

Ext.Ajax.request({
    url : 'http://192.168.10.90:8080/projectname/method',
    headers: {
        'Content-Type': 'application/json; charset=utf-8'
    },
    method: 'POST',
    params: Ext.JSON.encode({
        image: "imagebase64"
    }),
    success : function(response) {
        ........
    },
    failure : function(response) {
         .........
    }
});

I've tried several examples to enable the cors-filter in spring but none have worked. I don't know what else to do.

tartuzet
  • 21
  • 1
  • 4
  • See the answer at http://stackoverflow.com/questions/34949492/cors-request-with-preflight-and-redirect-disallowed-workarounds/39728229#39728229 for details of how to work around this. Also as noted there, this restriction on redirects is no longer in the spec but browsers need to update their implementations to match the spec change. – sideshowbarker Jan 18 '17 at 10:37

0 Answers0