重要信息,我在TestCase下运行所有这些.
我的网址是 http://my-MacBook-Pro.local:8080/myapi/v2/Driver/getDriver?domain=123&driver=125&key=9808098
如果我在Safari运行时粘贴此URL iPhone Simulator.它以JSON响应.我注意到我的catalina.out报告了这个请求.
我启用Allow HTTP Services了Settings->Developer.
这是代码段
print("fullurl ->"+urlComponents.url!.absoluteString)
URLSession.shared.dataTask(with: urlComponents.url!, completionHandler: {
        (data, response, error) in
        if(error != nil){
            print("error")
        }else{
            do{
                let json = try JSONSerialization.jsonObject(with: data!, options:.allowFragments) as! [String : AnyObject]
                print (json)
            }catch let error as NSError{
                print(error)
            }
        }
    }).resume()
编辑
参考 
添加以下内容info.plist,仍然我的http请求没有通过localhost运行tomcat的我的macport 8080
<dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>My-MacBook-Pro.local</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict> 
编辑
即使使用这些设置也可以尝试 …