启用了Cors的服务后,离子在休息服务中出现错误

编程入门 行业动态 更新时间:2024-10-10 19:20:47
本文介绍了启用了Cors的服务后,离子在休息服务中出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,我是ionic的新手.我想打电话给ionic服务,但是我总是会收到此错误; "

Hello I'm a newbie in ionic.I want to call post service in ionic but I always get this error ; ""

无法加载 mywebservice/api :对预检请求的响应未通过访问控制检查:当请求的凭据模式为包括"时,响应中访问控制允许-原始"标头的值不得为通配符"*".因此,不允许访问来源' localhost:8100 . XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制.

Failed to load mywebservice/api: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'localhost:8100' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

即使在高级Rest Service上也已在我的Web服务(nancyfx)中启用了Cors.

I have enable Cors in my web service (nancyfx) Even I check it on advanced Rest Service .

并致电ionic的邮政服务部门;

And call post service in ionic ;

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/api", headers, options )do(res => console.log(res)); enter code here

谢谢您的帮助!

推荐答案

我终于通过在web.config中添加这些内容来解决我的问题(在我的webservice中启用cors,nancyfx),(注意将自定义标头添加到Access -Control-Allow-Headers)

I finally solve my problem by adding these in web.config (enable cors in my webservice ,nancyfx) ,(be aware of adding your custom headers to the Access-Control-Allow-Headers)

<httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="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>

更多推荐

启用了Cors的服务后,离子在休息服务中出现错误

本文发布于:2023-10-30 04:50:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541820.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:离子   出现错误   Cors

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!