Angular 启用Cors服务的IONAL post in rest服务错误
你好,我是爱奥尼亚的新手。我想打电话给爱奥尼亚的邮政服务,但我总是遇到这个错误; “” 加载失败:对飞行前请求的响应未通过访问控制检查:当请求的凭据模式为“包括”时,响应中“访问控制允许来源”标头的值不得为通配符“*”。因此,不允许访问源“”。XMLHttpRequest启动的请求的凭据模式由withCredentials属性控制 我已经在我的web服务(nancyfx)中启用了Cors,即使我在高级Rest服务上检查了它 以及爱奥尼亚的邮电服务;Angular 启用Cors服务的IONAL post in rest服务错误,angular,rest,ionic-framework,nancy,Angular,Rest,Ionic Framework,Nancy,你好,我是爱奥尼亚的新手。我想打电话给爱奥尼亚的邮政服务,但我总是遇到这个错误; “” 加载失败:对飞行前请求的响应未通过访问控制检查:当请求的凭据模式为“包括”时,响应中“访问控制允许来源”标头的值不得为通配符“*”。因此,不允许访问源“”。XMLHttpRequest启动的请求的凭据模式由withCredentials属性控制 我已经在我的web服务(nancyfx)中启用了Cors,即使我在高级Rest服务上检查了它 以及爱奥尼亚的邮电服务; let headers = new
let headers = new HttpHeaders();
headers = headers
.set("Accept", "application/json")
.set("Content-Type", "application/json")
const params = new HttpParams();
const options = { headers, params, withCredentials: true };
return this.http
.post(
"mywebservice.com/api", headers, options
)do(res => console.log(res));
enter code here
感谢您的帮助 在ionic.config()中,需要设置以下行
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.useXDomain = true;
我最终通过在web.config中添加这些来解决问题(在我的web服务中启用cors,nancyfx),(注意将自定义头添加到访问控制允许头)
当您在advanced rest client上进行测试时,是否包含cookie以模拟带有凭据的设置?是的,我是为了与Arc一起使用而安装的当您在chrome中打开网络调试器时,是否看到针对您的带有凭据的请求将标头值设置为*?这可能是nancyfxYes上的某种错误配置。你是对的,我想这是关于nancyfx配置的。如果成功的话,我会做点什么,我会写在这里。我的directorty中没有ionic.config。你是指ionic.config.json吗?在应用程序的{“name”:“testmobile2018”,“app_id”:“type”:“ionic angular”,“integrations”:{“cordova”:{}}}}its.config()文件中,定义应用程序状态/路由和爱奥尼亚的基本设置。
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:8100"/>
<add name="Access-Control-Allow-Credentials" value="true"/>
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, Authorization, Content-Disposition, mycustomheaders!" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>
</customHeaders>
</httpProtocol>