// 1. 取出当前的cookies
NSArray<NSHTTPCookie *> *cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies;
// 2. 取出需要同步到的地址url
BESTHttpItem *httpItem = [BESTHttpHelper sharedHelper].curHttpItem;
NSString *url = [NSString stringWithFormat:@"%@/#/login", httpItem.frontend_addr]; // 3. 遍历cookies
for (NSHTTPCookie *cookie in cookies) {
// 4. 设置header的cookie信息
NSString *cookieString = [[NSString alloc] initWithFormat:@"%@=%@",[cookie name],[cookie value]];
NSDictionary *setCookieDic = [NSDictionary dictionaryWithObject:cookieString forKey:@"Set-Cookie"];
NSArray *headeringCookie = [NSHTTPCookie cookiesWithResponseHeaderFields:setCookieDic forURL:[NSURL URLWithString:url]]; // 5. 通过setCookies方法,完成设置,这样只要一访问URL为HOST的网页时,会自动附带上设置好的header
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:headeringCookie
forURL:[NSURL URLWithString:url]
mainDocumentURL:nil];
}

iOS UIWebView重定向Cookie的更多相关文章

  1. iOS UIWebView 和 WKWebView 的 cookie 获取,设置,删除

    Cookie简介说到Cookie,或许有些小伙伴会比较陌生,有些小伙伴会比较熟悉.如果项目中,所有页面都是纯原生来实现的话,一般Cookie这个东西或许我们永远也不会接触到.但是,这里还是要说一下Co ...

  2. iOS UIWebView清除缓存

    UIWebView清除Cookie: //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieSto ...

  3. ios UIWebView截获html并修改便签内容(转载)

    ios UIWebView截获html并修改便签内容 博客分类: iphone开发iphone开发phoneGap uiwebviewstringByEvaluatingJavaScriptFromS ...

  4. IOS UIWebView截获html并修改便签内容,宽度自适应

    需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果:  方法:通过js截获UIWebView中的html,然后修改html标签内容:  实例代码:  服 ...

  5. ios UIWebView截获html并修改便签内容

    需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果: 方法:通过js截获UIWebView中的html,然后修改html标签内容: 实例代码: 服务器端 ...

  6. iOS平台下cookie的使用

    iOS平台下cookie的使用 首先,先介绍下iOS对cookie的操作的两个类: 帖子来源于:http://blog.csdn.net/chun799/article/details/1720690 ...

  7. iOS UIWebView 获取内容实际高度,关闭滚动效果

    本文转载至 http://my.oschina.net/Khiyuan/blog/341535   iOS UIWebView 获取内容实际高度,关闭滚动效果 近期做东西,将 UIWebView 嵌套 ...

  8. iOS 代理 重定向消息 forwardInvocation

    今天简单研究一下iOS的重定向消息forwardInvocation: 首先看看Invocation类: @interface NSInvocation : NSObject { @private _ ...

  9. iOS UIWebView获取403/404

    问题描述 与WindowsPhone不同,iOS UIWebView并不认为403/404这种情况下页面访问是失败的,这也情有可原,但有时候,我们需要对WebView所遇到的403/404进行处理. ...

随机推荐

  1. C/C++ 结构体 数组 简单输入输出

    #include <stdio.h> #include <stdlib.h> struct student{ int num; ]; double dec; }; int ma ...

  2. 使用flume-ng聚合双活Nginx日志

    前不久使用Keepalived搭建了Nginx双活代理服务器,以达到一个公网IP后支持多个云主机的多个域名网站的目的.完成后又想在这双活的Nginx上有所有访问网站的日志,之前有了解过Google A ...

  3. 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分

    在实用VS编程的时候大家经常会遇到一个问题: 下面小编来为大家提供一个简单的解决方案: 1.在Windows中打开功能里输入regedit,回车打开注册表编辑器: 2.转到路径HKEY_LOCAL_M ...

  4. 将abc的全排列输出

    #include "iostream" using namespace std; void swap(char a[],int i,int j){ char temp; temp= ...

  5. mac下使用gcc

    1.下载安装macports:http://www.macports.org/install.php 安装完成之后,打开终端 2.在终端中输入 port install gcc_select 3.使用 ...

  6. WCF 、Web API 、 WCF REST 和 Web Service 的区别

    WCF .Web API . WCF REST 和 Web Service 的区别 The .Net framework has a number of technologies that allow ...

  7. FC400A与400B的区别

    FC400B就比400A多了一个功能,那就是联动,也就是说主机关了后,电子净化箱也会被关掉,这样就不需要去手动关闭电源,更加方便,估计是很多工业企业上需要这样的功能,所以就升级了这么个版本.

  8. python学习笔记之类class(第六天)

         参考文档:              1.金角大王博客:http://www.cnblogs.com/alex3714/articles/5188179.html               ...

  9. django 同步数据库

    http://www.jianshu.com/p/dbc4193b4f95 博主教程讲解比较详细,可做参考使用.

  10. Django(三)

    1.Django请求的生命周期         路由系统 -> 视图函数(获取模板+数据-->渲染) -> 字符串返回给用户   2.路由系统         /index/    ...