相同的URL,为什么urlsession出错,但使用NSURLConnection始终成功

时间:2017-03-28 09:49:41

标签: ios objective-c swift

    let url = URL(string: "https://soufunapp.3g.fang.com/http/sf2014.jsp?messagename=UserCount&wirelesscode=DD146FD49861797918ADA44B7E201180")

    let task = URLSession.shared.dataTask(with: URLRequest(url: url!)) { (data, response, error) in
        print("Always fail")
        if error != nil {
            print(error!)
        }
    }
    task.resume()

    NSURLConnection.sendAsynchronousRequest(URLRequest(url: url!), queue: OperationQueue.main) { (response, data, error) in
        print("always succeed")
    }
  

错误域= NSURLErrorDomain代码= -1001"请求超时。"   UserInfo = {NSUnderlyingError = 0x60000005ccb0 {错误   Domain = kCFErrorDomainCFNetwork Code = -1001"(null)"   UserInfo = {_ kCFStreamErrorCodeKey = -2102,_kCFStreamErrorDomainKey = 4}},   NSErrorFailingURLStringKey = https://soufunapp.3g.fang.com/http/sf2014.jsp?messagename=UserCount&wirelesscode=DD146FD49861797918ADA44B7E201180,   NSErrorFailingURLKey = https://soufunapp.3g.fang.com/http/sf2014.jsp?messagename=UserCount&wirelesscode=DD146FD49861797918ADA44B7E201180,   _kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2102,NSLocalizedDescription =请求超时。}

同样,使用Safari无法打开网址,但Chrome可以获取数据

0 个答案:

没有答案