我想使用IPAdress从我的服务器获取数据。我做了:
let url = NSURL(string: "http://51.255.XX.XXX/")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {
(data, response, error) in
if error == nil {
print(data)
}
else {
print("error")
}
我的输出是:
App Transport Security has blocked a cleartext HTTP (http://)
resource load since it is insecure.
Temporary exceptions can be configured via your app's Info.plist file.
我在互联网上检查了这个错误,我确实修改了我的info.plist,如:App Transport Security has blocked a cleartext HTTP resource。所以我添加了IP地址作为例外,如下所示:
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>http://51.255.XX.XXX/</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
如果我使用完全域名(http://www.domain.com)替换IP地址,我的代码可以正常工作,但是当我放置服务器的IP地址而不是domain.com时,我的代码就不行了
我的问题是,是否可以使用IP地址获取NSURL的数据?如果是,您是否有文件或示例给我?