I'm trying to use CORS to get data from another WS using ExtJS. The page that is calling this request is loaded over HTTPS and the requested page is HTTP.
Ext.Ajax.request({
url: 'http://MYDESTINATIONURL',
method: 'GET',
disableCaching: false ,
useDefaultXhrHeader: false,
cors: true,
success: function(response) {
console.log('SUCCESS!');
},
failure: function(response) {
console.log('FAILURE!: '+response.getAllResponseHeaders());
}
});
This request generates an OPTIONS method with a 405 (Method not Allowed) status. More details on the request: Request Method:OPTIONS Status Code:405 Method Not Allowed
Request Headers
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:x-requested-with
Access-Control-Request-Method:GET
Cache-Control:max-age=0
Connection:keep-alive
Host:MYDESTINATIONURL
Origin:https://localhost
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Response Headers
Access-Control-Allow-Headers:X-Requested-With,Content-Type
Access-Control-Allow-Origin:*
Access-Control-Request-Method:POST,GET,PUT,DELETE,OPTIONS
Allow:GET
Content-Length:1565
Content-Type:text/html; charset=UTF-8
Date:Tue, 22 Jul 2014 12:06:02 GMT
Server:Microsoft-HTTPAPI/2.0
The headers are according to CORS, I think. The request contains the Origin header and the response contains the -Allow-Origin header. The server supports CORS. What is causing the error though?
The error: OPTIONS http:// MYDESTINATIONURL 405 (Method Not Allowed) XMLHttpRequest cannot load http:// MYDESTINATIONURL. Invalid HTTP status code 405
I had the same problem as mentioned above, but resolved it by adding the following two lines during my application initialisation:
Ext.Ajax.useDefaultXhrHeader = false;
Ext.Ajax.cors = true;
Prior to this I had attempted to set the useDefaultXhrHeader
and cors
parameters on my store's AjaxProxy
without any success.
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.