ios - NSAllowsArbitraryLoads 不适用于 ip 地址

标签 ios macos ios9 xcode7

我正在尝试让我的应用程序通过 Apple Transport Security 连接到 152.111.198.244 的 http 服务器。我正在尝试的任何东西都不起作用。

将 NSAllowsArbitraryLoads 键添加到我的项目的 info.plist 文件仍然不允许我的应用程序连接到这个特定的 IP 地址 152.111.198.244 我已经完成了 technote关于 Apple 传输安全。我安装了 OSX 10.11 以尝试查找哪些设置可能适用于使用 URL

nscurl --ats-diagnostics http://152.111.198.244

nscurl --ats-diagnostics http://152.111.198.244/publications/

在终端中。 nscurl 尝试的所有设置都会失败。我看过类似的问题NSAllowsArbitraryLoads not workingNSExceptionAllowsInsecureHTTPLoads not working for ip addresses并没有找到解决方案。我也看了here并且那里提出的 NSExceptionMinimumTLSVersion key 不起作用。

我开始认为某处可能存在错误,或者我错过了什么。 IP 地址是 Apple Transport Security 的问题吗?为什么?有没有办法让 IP 地址通过 ATS 工作?

更新:我添加了给我带来麻烦的特定 IP 地址。希望有人能够复制我在说什么。

更新:我将此记录为雷达中的错误,并收到一条消息说它是重复的。同时,这个问题中提到的IP地址现在有一个域名http://3d.media24.com/但不幸的是,它并没有解决问题。

更新:我将答案标记为正确。苹果似乎用 XCode7.1 修复了这个问题,Apple Transport Security 的 key 也发生了一些变化。相关站点也已针对 https 连接进行了更新。

最佳答案

我能够访问该 URL,http://152.111.198.244 ,在 Xcode 7.1 和模拟器 9.1 下的我的 Info.plist 中使用“允许任意加载”:

  • 应用程序传输安全设置:字典
    • 允许任意加载:Boolean = YES

截图:

enter image description here

我使用了以下代码:

let url = NSURL(string: "http://152.111.198.244")!
let task = NSURLSession.sharedSession().dataTaskWithURL(url) {(data, response, error) -> Void in
    print("response \(response!)")
}
task.resume()

这是我收到的回复:

response <NSHTTPURLResponse: 0x7fe1a2421f80> { URL: http://152.111.198.244/auth/login } { status code: 200, headers {
    "Cache-Control" = "no-cache";
    Connection = "Keep-Alive";
    "Content-Encoding" = gzip;
    "Content-Length" = 1138;
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Fri, 23 Oct 2015 09:33:59 GMT";
    "Keep-Alive" = "timeout=5, max=98";
    Server = "Apache/2.4.7 (Ubuntu)";
    "Set-Cookie" = "XSRF-TOKEN=eyJpdiI6IldBOWYxcDk3SEtMekJ3YTNSUm9mYUE9PSIsInZhbHVlIjoiTFBcL3RGWW10cjlONFFkeXY1ZDA4SWRkSURIYlFsOGE3QkFEV3hRNTVwRFJuWSt5SXN3OU55Sng4elduMHd1T1duV0VFQ1o4dDVjeDJTZGRFeXJxMjN3PT0iLCJtYWMiOiJiZjNmOTg0NTZmY2RkMGQzNmE2YWEyNjJiNzA1MDlmZjIwM2M3NWYyNjYwZjM5N2Q3ZTgxNjRjNzAzMGYzYmMzIn0%3D; expires=Fri, 23-Oct-2015 11:33:59 GMT; Max-Age=7200; path=/, laravel_session=eyJpdiI6InR5OSs3cmpObVRBbFhORnVJQjRvWFE9PSIsInZhbHVlIjoiSTJ2bk41RVVLZUR1a0xKbFwvalZXQWpsNEtWeHppUVpYVUlRM1ZjQXc5aDJxT1wvXC9uYkViaTQ0SCtGNTMrdmtiQXFOd0VJTFwvM0ZCbmFHZk5MWlwvZ3BBUT09IiwibWFjIjoiYjRmNzcxY2Q5NDFlZjYzZTI1YzU2YzI0YTkxM2M0NDg0MGY2YThiODIxOGZjOTgxYjNmM2FlZTkzZGMyZTdjOCJ9; expires=Fri, 23-Oct-2015 11:33:59 GMT; Max-Age=7200; path=/; httponly";
    Vary = "Accept-Encoding";
    "X-Powered-By" = "PHP/5.5.9-1ubuntu4.11";
} }

我也能够使用命名域进行连接 3d.media24.com 但不能使用异常域的数字地址 152.111.198.244。

截图:

enter image description here

我的结果与 Apple Technote on App Transport Security 中异常域的定义一致:

A dictionary of exceptions for the named domain. The name of the key is the name of the domain–for example, www.apple.com.

关于ios - NSAllowsArbitraryLoads 不适用于 ip 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33034645/

相关文章:

ios - 使用 UIScrollview 将 .xib 显示为不同的页面?

ios - 为什么我的 Phonegap 应用程序覆盖了我移动设备的状态栏?

iphone - TBXML iOS 解析器中的内存泄漏

Ruby 1.8.7 世界可写检查? File.world_writable?只有 1.9.x

ios9 - MPNowPlayingInfoCenter 中 MPMediaItemPropertyArtwork 的大小应该是多少?

ios - Swift - 播放声音时出现错误 "fatal error: unexpectedly found nil while unwrapping an Optional value"

ios - 限制 iOS 上某些设备的旋转 - Swift

python - 中止陷阱 : 6 when running a python script

objective-c - Cocoa App 中的多重授权

ios - UITableView 中的自定义单元格(iOS 9)