CORS 405 (Method Not Allowed)

2019-01-28 22:17发布

i intend to send a cross-domain request to a soap web service using Ajax The url of the web service is: http://example1.asmx?op=GetVOD

My code:

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);

On the IIS 7 server side, i've already add these lines to the file 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" />

when i run the client code on Chrome, i have an 405 error:

http://example1.asmx?op=GetVOD 405 (Method Not Allowed)
http://example1.asmx?op=GetVOD Invalid HTTP status code 405

Does anyone know how to solve this ?

Thank in advance

1条回答
手持菜刀,她持情操
2楼-- · 2019-01-28 22:42

Sounds like Web DAV is getting in the way. Here's the config to remove it:

http://brockallen.com/2012/10/18/cors-iis-and-webdav/

查看更多
登录 后发表回答