美文网首页my ionic3我爱编程
ionic3 + angular5跨域问题的解决方案

ionic3 + angular5跨域问题的解决方案

作者: 竹子_331a | 来源:发表于2018-04-19 11:14 被阅读32次

最近在玩ionic3 ,底层angular版本是5.2,如下

"dependencies": {

"@angular/animations":"5.2.9",

"@angular/common":"5.2.9",

"@angular/compiler":"5.2.9",

"@angular/compiler-cli":"5.2.9",

"@angular/core":"5.2.9",

"@angular/forms":"5.2.9",

"@angular/http":"5.2.9",

"@angular/platform-browser":"5.2.9",

"@angular/platform-browser-dynamic":"5.2.9",

"@ionic-native/core":"4.6.0",

"@ionic-native/splash-screen":"4.6.0",

"@ionic-native/status-bar":"4.6.0",

"@ionic/storage":"2.1.3",

"ionic-angular":"3.9.2",

"ionicons":"3.0.0",

"rxjs":"5.5.8",

"sw-toolbox":"3.6.0",

"zone.js":"0.8.20"

}

本地有个springmvc项目,访问地址http://localhost:8088/xxx 

ionc的地址:http://localhost:8100/

很明显已经跨域了,如果只是简单的处理跨域问题,还是比较好处理的,但是涉及到cookie的跨域,那叫一个头痛,昨天搞了整整一天,翻遍国内外各大论坛,也没有一个真正的解决办法,最后只能自己研究了。

下面分享我的研究成果:

1、修改ionic访问的http请求的参数

that.http.get(url, {

withCredentials:true, //重点1,必须设置withCredentials:true

headers: {

'content-type':'application/x-www-form-urlencoded',//重点2:content-type为这个

},

params:params

})

2、安装谷歌插件Moesif CORS (安装地址 或者百度搜索Moesif Origin & CORS Changer)

3、设置Moesif CORS,选择trun on ,然后打开show detailed options

4、在打开的页面,拉到最下面,将Access-Control-Allow-Credentials: 设置为true,保存

5、好了,现在试试看吧,打印下session ,你会发现,两边已经同步了

相关文章

  • ionic3 + angular5跨域问题的解决方案

    最近在玩ionic3 ,底层angular版本是5.2,如下 "dependencies": { "@angula...

  • 跨域问题,解决方案

    跨域问题,解决方案 - Nginx反向代理跨域问题,解决方案 - CORS方案此为原作者的链接:跨域问题,解决之道

  • Web前后端跨域问题处理

    跨域问题有前台跨域(iframe间)和后台跨域。 前台跨域的解决方案可以采用跨域文档通讯(Cross domain...

  • 开发环境跨域和生产环境跨域

    开发环境跨域 前后端分离,IP地址不同,请求数据必然导致跨域问题;解决方案:proxy设置 生产环境跨域 解决方案...

  • Js请求跨域问题

    一、请求跨域问题概述 跨域:指的是协议名、端口或者域名不一致的情况都是跨域。 二、跨域问题的解决方案 1、同域代理...

  • ionic2-UIWebView(bug)

    在ionic3 iOS 中默认为 WKWebView,但是 WKWebView存在跨域的问题,但是UIWebVie...

  • 2、JS-Web-API知识点

    跨域问题:跨域的解决方案?教程: https://www.imooc.com/video/6238https://...

  • JWT简记

    JSON Web Token(JWT)是目前最流行的跨域认证解决方案。 跨域认证问题及传统解决方案 传统认证流程 ...

  • Spring Boot使用CORS解决跨域问题

    一、跨域问题描述 Web开发经常会遇到跨域问题,解决方案有:jsonp,iframe,CORS等等。CORS 与 ...

  • 跨域

    博客 说说跨域那些事儿 不要再问我跨域的问题了 前端常见跨域解决方案(全) 同源策略 JSONP(填充式JSON)...

网友评论

    本文标题:ionic3 + angular5跨域问题的解决方案

    本文链接:https://www.haomeiwen.com/subject/ioaikftx.html