我打算使用Ajax将跨域请求发送到soap Web服务。Web服务的URL是:http://example1.asmx?op = GetVOD
我的代码:
var url = 'http://example1.asmx?op=GetVOD'; var xhr = new XMLHttpRequest(); var strRequest = "<?xml version='1.0' encoding='utf-8'?>" + "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" + "<soap:Body>" + "<getVODTypeList xmlns='http://tv21.com/' />" + "</soap:Body>" + "</soap:Envelope>" xhr.open('POST', url, true); xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xhr.setRequestHeader("SOAPAction", "http://tv21.com/getVOD"); xhr.send(strRequest);
在IIS 7服务器端,我已经将这些行添加到文件web.config中
<add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" /> <add name="Access-Control-Allow-Headers" value="Content-Type" />
当我在Chrome上运行客户端代码时,出现405错误:
http://example1.asmx?op=GetVOD 405 (Method Not Allowed) http://example1.asmx?op=GetVOD Invalid HTTP status code 405
有谁知道如何解决这个问题?
预先感谢
听起来像Web DAV正在阻碍。这是删除它的配置:
http://brockallen.com/2012/10/18/cors-iis-and- webdav/