简体   繁体   中英

Cors request method PUT is not allowed by Access-Control-Allow-Methods

I'm using Cors requests to communicate between my client and server placed in two different domain.

I configurate my apache http server this way it's using SSL :

//with AJAX withCredentials=true (cookies sent, SSL allowed...)
SetEnvIfNoCase ORIGIN (.*) ORIGIN=$1
Header always set Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, PATCH, DELETE" 
Header always set Access-Control-Allow-Origin "%{ORIGIN}e"
Header always set Access-Control-Allow-Credentials "true"
Header always set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L,E=HTTP_ORIGIN:%{HTTP:ORIGIN}]

My ajax request is like this :

$.ajax({   url: URL,
                        type: 'PUT',
                      xhrFields: {
                           withCredentials: true
                        },
                        crossDomain: true,
                        data: userPreferences, 
                        success: function() { }
                    });
$.ajax({   url: URL,
                        type: 'GET',
                      xhrFields: {
                           withCredentials: true
                        },
                        crossDomain: true,                              
                        success: function() { }
                    });

The result of this configuration is, my get request is working but not my put request,i get the following error in google chrome console ( itried it with firefox )

 XMLHttpRequest cannot load https://URL. Method PUT is not allowed by Access-Control-Allow-Methods.

How can i fix this ?

I have misstyped this line on my apache config

Header always set Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, PATCH, DELETE"

i typed method without S that's why i got this error :

XMLHttpRequest cannot load https://URL. Method PUT is not allowed by Access-Control-Allow-Methods.

Anyway all the configurations i wrote above is a tested/working solution to enable cors with SSL.

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