我可以使用标准的jquery ajax调用来访问我的web api服务:
$.ajax('http://service/method', {
contentType: 'application/json',
type: 'GET',
xhrFields: {
withCredentials: true
}
})在服务器端,webconfig文件配置如下:
<customHeaders>
<clear/>
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Allow-Origin" value="http://localhost:1502" />
<add name="Access-Control-Allow-Headers" value="Content-Type,X-Requested-With, Authorization" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>目前,我正在尝试从运行在端口1502上的本地网站访问该服务。
但是,在使用breeze时,我不知道如何指定withCredential参数,因此得到了一个401错误。
发布于 2017-03-31 23:12:43
我尝试了上面的方法,但在BreezeJS 1.6.3版本中似乎不起作用。
然而,我能够让它在稍微改变的情况下工作。以下是我的工作代码:
// set credentials on
var ajaxAdapter = breeze.config.getAdapterInstance('ajax');
ajaxAdapter.defaultSettings = {
withCredentials: true
};https://stackoverflow.com/questions/17273842
复制相似问题