美文网首页
Swift 原生的网络请求

Swift 原生的网络请求

作者: 吉林天师 | 来源:发表于2019-08-27 16:25 被阅读0次

    注意设置plist文件中的 AppTransport

           let str = "https://lanhuapp.com/web/#/item/project/board/detail?type=share_mark&pid=0424f944-7878-42f5-bef5-60caf0f9fa3a&activeSectionId=&teamId=8b236f9d-7a13-4b41-8170-99696b04efe7&param=c47046a3-0abb-423b-b4ff-007e02c1a869&project_id=0424f944-7878-42f5-bef5-60caf0f9fa3a&image_id=93c25942-7ba9-444e-9405-5f4eb0335c2f"
            let url : NSURL =  NSURL(string: str)! as URL as URL as NSURL
            let request = URLRequest(url: url as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 30)
            let session = URLSession.shared
            let dataTask = session.dataTask(with: request) { (data, respons, error) in
                
                print(error as Any)
                if data == nil {return}
                if respons == nil {return}
                
                let str = String(data: data!, encoding: .utf8)
                print(str as Any)
                print(respons!)
            }
            dataTask.resume()
    
    

    相关文章

      网友评论

          本文标题:Swift 原生的网络请求

          本文链接:https://www.haomeiwen.com/subject/ucgeectx.html