2
我打算髮送跨域請求,使用Ajax Web服務的URL SOAP Web服務是:http://example1.asmx?op=GetVODCORS 405(不允許的方法)
我的代碼:
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的服務器端,我已經這些線當我運行在Chrome上的客戶端代碼添加到該文件的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" />
,我有一個405錯誤:
http://example1.asmx?op=GetVOD 405 (Method Not Allowed)
http://example1.asmx?op=GetVOD Invalid HTTP status code 405
有沒有人知道如何解決這個問題?
預先提前感謝
謝謝您的回答,但遺憾的是它並沒有爲我工作(我使用的是IIS 7.5)。經過2天的研究,我發現避免「405方法不允許」的唯一工作解決方案是在Application_BeginRequest方法中定義CORS頭文件,正如本答案中提到的http://stackoverflow.com/a/14631068/ 827168 – pomeh