我正在开发一个使用 xmlHttpRequest 从服务器上的 xml 获取 DOM 元素位置的组件。拖放后,我用新位置更新 xml,并且我想通过 XMLHttpRequest 将其发回服务器以更新同一文件。
responseText 消息指出 HTTP 错误 405.0 - 不允许的方法。由于使用了无效方法(HTTP 动词),因此无法显示您正在查找的页面。
我检查了 applicationhost.config 文件,看起来每个处理程序都使用 POST 方法进行配置。还开启了Win 7组件上IIS的所有功能。
我的电脑:Win7 家庭基本版、Visual Studio 专业版、IIS 7.5 Express。
pe:我不使用 webrequest 方法,因为主要使用 javascript 进行更新过程,因为 mootools 库的拖放功能。
先感谢您!
I am working on a component which uses xmlHttpRequest to get DOM element positions from a xml on the server. Than after drag and drop I update the xml with the new positions and I want to post it back via XMLHttpRequest to the server to update the same file.
The responseText message states that HTTP Error 405.0 - Method Not Allowed. The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
I checked the applicationhost.config file and looks like every handler is configured with POST method. Also turned on all the features of IIS on Win 7 components.
My pc: Win7 home basic, visual studio professional, iis 7.5 express.
p.e.: I don't use webrequest method since mainly using javascript for the update process, because of the drag and drop functionality of the mootools library.
Thank you in advance!
发布评论
评论(3)
您在评论中提到的配置设置了用于处理“静态文件”的默认 IIS 模块,即通过基于将 URI 路径映射到文件系统来返回文件来响应 GET 请求。
这些设置用于处理所有动词,但对除 GET 和 HEAD 之外的所有动词进行 405 处理,因为这是“静态文件”的默认 IIS 行为,即拒绝允许将它们发布到(或放入或删除)。
因此,错误在于您要发布到的 URI 没有映射到用于处理 javascript 正在发布的数据的处理程序。如果该处理程序是 ASPX 页面,则检查其他 ASPX 页面是否正常工作以及是否使用了正确的 URI。然后尝试使用一个简单的 HTML 表单来调试它,该表单会 POST 适当的数据(甚至是不适当的数据,这样您至少可以获得有关数据错误的错误消息,而不是最终出现在根本拒绝处理 POST 的地方)。
如果处理 POST 的代码位于
IHttpModule
或IHttpHandler
中,那么您需要向 web.config 添加一些内容以覆盖 URI 的默认值问题。The configuration you mention in your comment, sets the default IIS modules for handling "static files", that is responding to GET requests by returning a file based on mapping the URI path to the file system.
These are set up to handle all verbs but to 405 to everything except GET and HEAD because that is the default IIS behaviour for "static files" is to refuse to allow them to be POSTed to (or PUT to, or DELETEd).
The bug therefore is that the URI you are POSTing to isn't mapping to your handler for dealing with the data the javascript is POSTing. If that handler is an ASPX page, then check that other ASPX pages are working and that the correct URI is used. Then try debugging it with a simple HTML form that POSTs appropriate data (or even inappropriate data so you can at least get an error message about the data being wrong rather than it ending up somewhere that refuses to handle POST at all).
If the code to handle the POST is in an
IHttpModule
orIHttpHandler
, then you need to add something to the web.config to override the default for the URI(s) in question.您的组件和处理来自同一来源的 XMLHttpRequest 的服务器是否相同? IE。它是否由相同的协议://主机:端口组合提供服务。如果没有,浏览器将发出 HTTP OPTIONS 而不是您期望的 POST。要处理这种情况,可以执行以下操作:
JSONP
跨域资源共享
Is your component and the server handling the XMLHttpRequests served from the same origin? Ie. is it served from the same, protocol://host:port combination. If not, the browser will issue a HTTP OPTIONS instead of the POST you are expecting it to. To handle this situation either do:
JSONP
Cross-origin resource sharing
我将结束此对话,因为该问题已通过 WebService 的 JSON 请求和对象映射得到解决。我认为问题是与目录上的本地权限配置有关的安全问题。
感谢您的帮助!
科内尔
I am closing this conversation since the issue was resolved with JSON request and object mapping via WebService. I assume the problem was a security one regarding to local permission configuration on the directory.
Thank you for your help!
Kornél