简体   繁体   English

使用ExtJS的CORS返回错误405(不允许使用方法)

[英]CORS using ExtJS returns error 405 (Method not Allowed)

I'm trying to use CORS to get data from another WS using ExtJS. 我正在尝试使用CORS从另一个使用ExtJS的WS获取数据。 The page that is calling this request is loaded over HTTPS and the requested page is HTTP. 调用此请求的页面是通过HTTPS加载的,请求的页面是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. 该请求将生成状态为405(不允许使用方法)的OPTIONS方法。 More details on the request: Request Method:OPTIONS Status Code:405 Method Not Allowed 有关请求的更多详细信息:请求方法:OPTIONS状态码:405方法不允许

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. 我认为标题是根据CORS编写的。 The request contains the Origin header and the response contains the -Allow-Origin header. 该请求包含Origin头,响应包含-Allow-Origin头。 The server supports CORS. 服务器支持CORS。 What is causing the error though? 是什么导致了错误?

The error: OPTIONS http:// MYDESTINATIONURL 405 (Method Not Allowed) XMLHttpRequest cannot load http:// MYDESTINATIONURL. 错误:选项http:// MYDESTINATIONURL 405(不允许使用方法)XMLHttpRequest无法加载http:// MYDESTINATIONURL。 Invalid HTTP status code 405 无效的HTTP状态代码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. 在此之前,我曾尝试在商店的AjaxProxy上设置useDefaultXhrHeadercors参数,但没有成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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