iOS Https

iOS9应用安全-NSURLRequest默认协议修改为https

2015-06-12 11:13:32

今天把现有APP在IOS9上编译了一次发现,所有请求都是timeout

2015-06-12 10:32:42.087 mcapp[8300:226922] Failed:Error 
Domain=NSURLErrorDomain Code=-1001 "The request timed out." 
UserInfo=0x7f9b18cdc420 {NSUnderlyingError=0x7f9b18f49e80 "The request timed 
out.", NSErrorFailingURLStringKey=https://***.maichong.me/***/share-data?, 
NSErrorFailingURLKey=https://***.maichong.me/***/share-data?, 
_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, 
NSLocalizedDescription=The request timed out.}

webView加载URL:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://image.html"]]];

输出日志:

shouldStartLoadWithRequest url: http://image.html
shouldStartLoadWithRequest url: https://image.html
shouldStartLoadWithRequest url: http://image.html
didFailLoadWithError error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x14e989f0 {NSErrorFailingURLKey=http://image.html, NSErrorFailingURLStringKey=http://image.html}
shouldStartLoadWithRequest url: https://image.html
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

仔细看了一下发现协议被修改成了https协议,难道是IOS9搞得鬼?

于是去查了一下IOS9的文档

果然找到这么一段:App Transport Security

App Transport Security

App Transport Security (ATS) lets an app add a declaration to its Info.plist 
file that specifies the domains with which it needs secure communication. ATS 
prevents accidental disclosure, provides secure default behavior, and is easy 
to adopt. You should adopt ATS as soon as possible, regardless of whether 
you’re creating a new app or updating an existing one.

If you’re developing a new app, you should use HTTPS exclusively. If you have 
an existing app, you should use HTTPS as much as you can right now, and create 
a plan for migrating the rest of your app as soon as possible.

正如上面说的provides secure default behavior,现在https在iOS9上是默认的。并且劝告开发者尽可能使用https协议,而且要把需要开启https协议的域名在info.plist里声明。

解决方法

在info.plist里设置ATS

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

然后重新编译运行。

后记

苹果这次iOS9强制启用https,可能是受之前应用安全问题的考虑,还是希望大家都改成https协议,所以赶紧和服务器端商量,准备全面迁移到https协议上。


标签:  https  iOS9  Security  NSURLRequest
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值