Ext.data.proxy.Rest提交至*.ashx时出现"HTTP Error 405.0 - Method not allowed" 解决方法

  今天使用Ext.data.proxy.Rest将一个Extjs的数据模型提交给一个*.ashx文件时,出现 HTTP Error 405.0 - Method not allowed 错误

    查看控制台,发现Ext.data.proxy.Rest是以PUT方式提交的,而错误信息提示,只能以GET,HEAD,POST,DEBUG提交。经过一番折腾,终于在微软的网站上找到答案,下面是解决方法:

      Error message when a user visits a Web site that is hosted on a server that is running Internet Information Services 7.0: "HTTP Error 405.0 - Method not allowed"

     当用户访问一个运行在Internet Information Services 7.0的网站时出现“HTTP Error 405.0 - Method not allowed”的错误信息

  Cause 1

   This problem occurs because the client makes an HTTP request by using an HTTP method that does not comply with the HTTP specifications. To resolve this problem, see Resolution 1.

  原因 1

  这个问题的发生是因为客户端在发生HTTP请求时使用的HTTP方式不是HTTP规定中所支持的,解决此问题请查看解决方法1

  Cause 2

  This problem occurs because a client makes an HTTP request by sending the POST method to a static HTML page. Static HTML pages do not support the POST method. To resolve this problem, see Resolution 2

  原因 2

  这个问题的发生是因为客户端将一个POST方式的HTTP请求发送至一个静态的HTML页面,静态的HTML页面不支持POST方式的请求。解决该问题,请查看解决方法2

  Resolution 1

      Make sure that the client sends a request that contains a valid HTTP method. To do this, follow these steps:

  1. Click Start, type Notepad in the Start Search box, right-click Notepad, and then click Run as administrator.
         Note If you are prompted for an administrator password or for a confirmation, type the password, or click Continue.

  2.On the File menu, click Open. In the File name box, type %windir%\system32\inetsrv\config\applicationhost.config
         and then click  Open.In the ApplicationHost.config file, locate the <handlers> tag.

  3.Make sure that all the handlers use valid HTTP methods.

Save the ApplicationHost.config file.

  解决方法 1

  使客户端的请求方式是一个有效方式,为了达到该目标,请参照以下步骤:

  1. 单击开始,在开始搜索栏中键入 Notpead,在结果栏中右键单击 Notepad ,选择以管理员身份运行

          注意 如果系统提示你输入管理员密码或进行确认,请键入密码或单击继续

  2. 在文件菜单中,选择打开. 在文件名输入框中键入:%windir%\system32\inetsrv\config\applicationhost.config ,然后选择打开

  3. 在 ApplicationHost.config 文件中定位到 <handlers> 标签

  4. 确认所有的处理方式使用的是你需要的HTTP方式。

  5. 保存 ApplicationHost.config 文件

  Resolution 2

  Instead of making the HTTP request to a static HTML page, make the HTTP request by sending the POST method to an Active Server Pages (ASP) page.

  解决方法 2

  将原先向一个静态HTML页面发送的POST方式的HTTP请求替换为发送给一个Active Server Pages(ASP) 页面。

附:

  -> 单击此处转向微软的解决方案原文地址

  

      另:通过Extjs本身来解决该问题

      通过分析Extjs的源代码及API发现请求是通过Extjs的Proxy组件发出来的

      Ext.data.proxy.Rest是继承自Ext.data.proxy.Ajax,但actionMethods是覆盖了Ext.data.proxy.Ajax原有的。

      Ext.data.proxy.Ajax的actionMethods:       

1     actionMethods: {
2         create : 'POST',
3         read   : 'GET',
4         update : 'POST',
5         destroy: 'POST'
6     }

 

      Ext.data.proxy.Rest的actionMethods:

1     actionMethods: {
2         create : 'POST',
3         read   : 'GET',
4         update : 'PUT',
5         destroy: 'DELETE'
6     }

 

API中也对actionMethods作过解释:

 

Mapping of action name to HTTP request method. These default to RESTful conventions for the 'create', 'read', 'update' and 'destroy' actions (which map to 'POST', 'GET', 'PUT' and 'DELETE' respectively). This object should not be changed except globally via Ext.override - the getMethod function can be overridden instead.

我们可以通过Ext.override的方法去得到我们想要设置的actionMethods:

 1 Ext.override(Ext.data.proxy.Rest, {
 2 
 3      actionMethods: {
 4         create : 'POST',
 5         read   : 'GET',
 6         update : 'POST',
 7         destroy: 'POST'
 8     }
 9 
10 });

转载于:https://www.cnblogs.com/pivots/archive/2012/05/10/2494114.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值