从 IE 调用 webservice 工作,而不是从 Chrome 或 Firefox
Posted
技术标签:
【中文标题】从 IE 调用 webservice 工作,而不是从 Chrome 或 Firefox【英文标题】:Call webservice works from IE, not from Chrome or Firefox 【发布时间】:2015-07-10 13:21:10 【问题描述】:我在我的网站的同一个域中有一个网络服务。我有一个 ajax 调用来咨询该 Web 服务,并且在 IE 中可以正常工作,但在 Chrome 和 Firefox 中,我无法使其正常工作。
我的 ajax 调用是:
$.ajax(
type: 'POST',
async: false
data: xml,
url: url,
dataType: "xml",
success: function (data, textStatus, XmlHttpRequest)
//On sucess action
,
error: function (XMLHttpRequest, textStatus, errorThrown)
//On error action
,
headers:
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": soapAction,
"Content-Length": xml.length + 1
);
但我从 chrome 和 firefox 收到:
XMLHttpRequest cannot load https://mydomain:83/<webservice>/<webservice>.asmx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://mydomain' is therefore not allowed access. The response had HTTP status code 500.
我添加到 webconfig:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="https://mydomain"/>
<add name="Access-Control-Allow-Origin" value="http://mydomain"/>
<add name="Access-Control-Allow-Credentials" value="true"/>
</customHeaders>
</httpProtocol>
但没有运气。知道我错过了什么吗?
【问题讨论】:
【参考方案1】:我很快就放弃了。在我的特殊情况下,这对 Chrome 和 Firefox 有用
<add name="Access-Control-Allow-Origin" value="https://mydomain" />
<add name="Access-Control-Allow-Headers" value="Content-Type, SOAPAction" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
【讨论】:
以上是关于从 IE 调用 webservice 工作,而不是从 Chrome 或 Firefox的主要内容,如果未能解决你的问题,请参考以下文章
如何在android中调用localhost的webservice(来自wamp或xampp服务器)?